The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DefaultController.cs 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. }
  42. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
  43. public class MyAuthorizeAttribute : AuthorizeAttribute
  44. {
  45. protected override bool AuthorizeCore(HttpContextBase httpContext)
  46. {
  47. if (httpContext == null)
  48. throw new ArgumentNullException("httpContext");
  49. var user = httpContext.User;
  50. if (!user.Identity.IsAuthenticated)
  51. return false;
  52. return true;
  53. }
  54. }
  55. }