The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StreamController.cs 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using Teknik.Areas.Stream.ViewModels;
  8. using Teknik.Controllers;
  9. using Teknik.Filters;
  10. namespace Teknik.Areas.Stream.Controllers
  11. {
  12. public class StreamController : DefaultController
  13. {
  14. [TrackPageView]
  15. [AllowAnonymous]
  16. public ActionResult Index()
  17. {
  18. ViewBag.Title = "Teknikam";
  19. StreamViewModel model = new StreamViewModel();
  20. return View(model);
  21. }
  22. [HttpGet]
  23. [AllowAnonymous]
  24. public FileStreamResult ViewStream(int id)
  25. {
  26. try
  27. {
  28. if (Config.StreamConfig.Enabled)
  29. {
  30. if (id > 0 && id <= Config.StreamConfig.Sources.Count)
  31. {
  32. // ID is valid, so let's get the stream
  33. string source = Config.StreamConfig.Sources[id - 1];
  34. //Create a WebRequest to get the file
  35. HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(source);
  36. //Create a response for this request
  37. HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse();
  38. return File(fileResp.GetResponseStream(), fileResp.ContentType);
  39. }
  40. }
  41. }
  42. catch (Exception)
  43. {
  44. }
  45. return null;
  46. }
  47. }
  48. }