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.

DefaultController.cs 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using System.Web.Routing;
  7. using Teknik.Areas.Error.Controllers;
  8. using Teknik.Areas.Error.ViewModels;
  9. using Teknik.Configuration;
  10. using Piwik.Tracker;
  11. using Teknik.Filters;
  12. using Teknik.Helpers;
  13. using Teknik.ViewModels;
  14. namespace Teknik.Controllers
  15. {
  16. [CORSActionFilter]
  17. public class DefaultController : Controller
  18. {
  19. private Config _config;
  20. protected string Subdomain
  21. {
  22. get { return (string)Request.RequestContext.RouteData.Values["sub"]; }
  23. }
  24. protected Config Config
  25. {
  26. get
  27. {
  28. if (_config == null)
  29. {
  30. _config = Config.Load();
  31. }
  32. return _config;
  33. }
  34. }
  35. public DefaultController()
  36. {
  37. ViewBag.Title = Config.Title;
  38. ViewBag.Description = Config.Description;
  39. if (Response != null)
  40. {
  41. Response.SuppressFormsAuthenticationRedirect = true;
  42. }
  43. }
  44. // Get the Favicon
  45. [HttpGet]
  46. [AllowAnonymous]
  47. public ActionResult Favicon()
  48. {
  49. // Get favicon
  50. string imageFile = Server.MapPath(Constants.FAVICON_PATH);
  51. return File(imageFile, "image/x-icon");
  52. }
  53. // Get the Logo
  54. [HttpGet]
  55. [AllowAnonymous]
  56. public ActionResult Logo()
  57. {
  58. // Get favicon
  59. string imageFile = Server.MapPath(Constants.LOGO_PATH);
  60. return File(imageFile, "image/svg+xml");
  61. }
  62. [HttpGet]
  63. [AllowAnonymous]
  64. public ActionResult NotFound()
  65. {
  66. var errorController = new ErrorController();
  67. if (errorController != null)
  68. {
  69. return errorController.Http404(new Exception("Page Not Found"));
  70. }
  71. return null;
  72. }
  73. protected ActionResult GenerateActionResult(object json)
  74. {
  75. return GenerateActionResult(json, View());
  76. }
  77. protected ActionResult GenerateActionResult(object json, ActionResult result)
  78. {
  79. if (Request.IsAjaxRequest())
  80. {
  81. return Json(json);
  82. }
  83. return result;
  84. }
  85. }
  86. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
  87. public class MyAuthorizeAttribute : AuthorizeAttribute
  88. {
  89. protected override bool AuthorizeCore(HttpContextBase httpContext)
  90. {
  91. if (httpContext == null)
  92. throw new ArgumentNullException("httpContext");
  93. var user = httpContext.User;
  94. if (!user.Identity.IsAuthenticated)
  95. return false;
  96. return true;
  97. }
  98. }
  99. }