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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. namespace Teknik.Controllers
  13. {
  14. public class DefaultController : Controller
  15. {
  16. private Config _config;
  17. protected string Subdomain
  18. {
  19. get { return (string)Request.RequestContext.RouteData.Values["sub"]; }
  20. }
  21. protected Config Config
  22. {
  23. get
  24. {
  25. if (_config == null)
  26. {
  27. _config = Config.Load();
  28. }
  29. return _config;
  30. }
  31. }
  32. public DefaultController()
  33. {
  34. ViewBag.Title = Config.Title;
  35. ViewBag.Description = Config.Description;
  36. if (Response != null)
  37. {
  38. Response.SuppressFormsAuthenticationRedirect = true;
  39. }
  40. }
  41. // Get the Favicon
  42. [HttpGet]
  43. [AllowAnonymous]
  44. public ActionResult Favicon()
  45. {
  46. // Get favicon
  47. string imageFile = Server.MapPath("~/Images/favicon.ico");
  48. return File(imageFile, "image/x-icon");
  49. }
  50. // Get the Logo
  51. [HttpGet]
  52. [AllowAnonymous]
  53. public ActionResult Logo()
  54. {
  55. // Get favicon
  56. string imageFile = Server.MapPath("~/Images/logo-black.svg");
  57. return File(imageFile, "image/svg+xml");
  58. }
  59. }
  60. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
  61. public class MyAuthorizeAttribute : AuthorizeAttribute
  62. {
  63. protected override bool AuthorizeCore(HttpContextBase httpContext)
  64. {
  65. if (httpContext == null)
  66. throw new ArgumentNullException("httpContext");
  67. var user = httpContext.User;
  68. if (!user.Identity.IsAuthenticated)
  69. return false;
  70. return true;
  71. }
  72. }
  73. }