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 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. [TrackingFilter]
  15. public class DefaultController : Controller
  16. {
  17. private Config _config;
  18. protected string Subdomain
  19. {
  20. get { return (string)Request.RequestContext.RouteData.Values["sub"]; }
  21. }
  22. protected Config Config
  23. {
  24. get
  25. {
  26. if (_config == null)
  27. {
  28. _config = Config.Load();
  29. }
  30. return _config;
  31. }
  32. }
  33. public DefaultController()
  34. {
  35. ViewBag.Title = Config.Title;
  36. ViewBag.Message = Config.Description;
  37. if (Response != null)
  38. {
  39. Response.SuppressFormsAuthenticationRedirect = true;
  40. }
  41. }
  42. }
  43. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
  44. public class MyAuthorizeAttribute : AuthorizeAttribute
  45. {
  46. protected override bool AuthorizeCore(HttpContextBase httpContext)
  47. {
  48. if (httpContext == null)
  49. throw new ArgumentNullException("httpContext");
  50. var user = httpContext.User;
  51. if (!user.Identity.IsAuthenticated)
  52. return false;
  53. return true;
  54. }
  55. }
  56. }