DefconDotNet

Untitled

Oct 19th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1.  
  2.         protected void Application_AcquireRequestState(object sender, EventArgs e)
  3.         {
  4.             var httpContext = HttpContext.Current;
  5.             var session = httpContext.Session;
  6.  
  7.             if (User.Identity.IsAuthenticated && session["UserRole"]==null) {
  8.                 var identity = new GenericIdentity(string.Empty, string.Empty);
  9.                 httpContext.User = new GenericPrincipal(identity, new string[] { });
  10.                 FormsAuthentication.SignOut();
  11.                 Session.Clear();
  12.             }
  13.             else if ( session["UserRole"] != null)
  14.                 switch ((UserRoles)session["UserRole"])
  15.                 {
  16.                     case UserRoles.Adminstrator:
  17.                         httpContext.User = new GenericPrincipal(httpContext.User.Identity, new[] {"Administrator"});
  18.                         break;
  19.                     case UserRoles.Customer:
  20.                         httpContext.User = new GenericPrincipal(httpContext.User.Identity, new[] {"Customer"});
  21.                         break;
  22.                     case UserRoles.Client:
  23.                         httpContext.User = new GenericPrincipal(httpContext.User.Identity, new[] {"Client"});
  24.                         break;
  25.                 }
  26.         }
Advertisement
Add Comment
Please, Sign In to add comment