郑州颐和随访系统

Global.asax.cs 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.Interface.Models.Common;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Web;
  8. using System.Web.Mvc;
  9. using System.Web.Routing;
  10. using System.Web.Script.Serialization;
  11. using System.Web.Security;
  12. namespace CallCenterApi.Interface
  13. {
  14. public class MvcApplication : System.Web.HttpApplication
  15. {
  16. protected void Application_Start()
  17. {
  18. AreaRegistration.RegisterAllAreas();
  19. RouteConfig.RegisterRoutes(RouteTable.Routes);
  20. //clq 增加异常日志记录 自定义 HandleErrorAttribute
  21. FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
  22. }
  23. protected void Application_AuthenticateRequest(object sender, EventArgs e)
  24. {
  25. HttpApplication app = (HttpApplication)sender;
  26. var context = app.Context;
  27. if (context == null) throw new ArgumentNullException("context");
  28. var token = context.Request["token"];
  29. if (string.IsNullOrWhiteSpace(token)) return;
  30. try
  31. {
  32. ////获取缓存
  33. //var dict = CacheHelper.Get(token);
  34. //获取redis缓存
  35. var dict = RedisHelper.StringGet(CommonHelper.MD5(token));
  36. if (dict == null) return;
  37. Cache.Models.CurrentUserInfo userData = null;
  38. //获取FormsAuthenticationTicket对象
  39. FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(token);
  40. if (ticket != null && string.IsNullOrEmpty(ticket.UserData) == false)
  41. userData =ticket.UserData.ToObject<Cache.Models.CurrentUserInfo>(); //还原用户数据
  42. if (ticket != null && userData != null)
  43. context.User = new FormsPrincipal<Cache.Models.CurrentUserInfo> (ticket, userData);//重新给context.User赋值。
  44. }
  45. catch { /* 有异常也不要抛出,防止攻击者试探。 */ }
  46. }
  47. }
  48. }