Guest User

Untitled

a guest
May 9th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. public virtual void OnAuthorization(AuthorizationContext filterContext)
  2. {
  3. if (filterContext == null)
  4. {
  5. throw new ArgumentNullException("filterContext");
  6. }
  7.  
  8.  
  9. string auth = filterContext.HttpContext.Request.Headers["authorization"];
  10.  
  11. if (!String.IsNullOrEmpty(auth))
  12. {
  13. byte[] encodedDataAsBytes = Convert.FromBase64String(auth.Replace("Basic ", ""));
  14. string val = Encoding.ASCII.GetString(encodedDataAsBytes);
  15. string userpass = val;
  16. string user = userpass.Substring(0, userpass.IndexOf(':'));
  17. string pass = userpass.Substring(userpass.IndexOf(':') + 1);
  18.  
  19. if (!System.Web.Security.Membership.Provider.ValidateUser(user, pass))
  20. {
  21. filterContext.Result = new HttpUnauthorizedResult();
  22. }
  23.  
  24. }
  25. else
  26. {
  27. if (AuthorizeCore(filterContext.HttpContext))
  28. {
  29.  
  30.  
  31. HttpCachePolicyBase cachePolicy = filterContext.HttpContext.Response.Cache;
  32. cachePolicy.SetProxyMaxAge(new TimeSpan(0));
  33. cachePolicy.AddValidationCallback(CacheValidateHandler, null /* data */);
  34. }
  35. else
  36. {
  37. // auth failed, redirect to login page
  38. filterContext.Result = new HttpUnauthorizedResult();
  39. }
  40. }
  41.  
  42.  
  43. }
Add Comment
Please, Sign In to add comment