c# - Set HttpContext.Current.User from Thread.CurrentPrincipal -


If I have a security manager in my application that works for both Windows and Web, the process is simple, just the user Takes and PWD and certifies against a database, then sets the thread. This works fine for windows applications with Custom Principal Custom Principal, but I have problems with web applications.

After the authentication process, when I am trying to set the present. Custom Principal users from thread Current Principal This last one is a generic principal, is there anything wrong with me? This is my code:

Login.aspx

  protected void btnAuthenticate_Click (object sender, EventArgs e) {SecurityManager.Authenticate ( "user", "pwd"); // This is where I set custom prints in the thread. Current principal Formsatifikeshntiket Pramanikrntat = new Formatifikeshntiket (1, "user", Dinanktaim. Now, Dinanktaimkab. Additional Minugh (30), false, ""); String Tickets = Formatting Encrypt HttpCookie authenticationKook = new HTTP cookie (form notification.firmquickname, ticket); Response.Cookies.Add (authenticationCookie); Response.Redirect (FormsAuthentication.GetRedirectUrl ("user", incorrect)); }  

Global.asax (this is where the problem appears)

  protected void Application_AuthenticateRequest (object sender, EventArgs e) {HttpCookie authCookie = Context.Request .Cookies [FormsAuthentication.FormsCookieName]; If return (authCookie == faucet); If (HttpContext.Current.User = null & amp ;! & amp; HttpContext.Current.User.Identity.IsAuthenticated & amp; & amp; is HttpContext.Current.User.Identity FormsIdentity) {HttpContext.Current.User = System. Threading.Thread. CurrentPrincipal; // here Price GenericPrincipal}  

Thanks in advance for any help.

First of all: You must set up Prince on each request.

Form authentication uses the principal's own assignment on each request. That is why you GenericPrincipal

I usually assigned to your custom principal re OnPostAuthenticate when standard authentication mechanism.

are viewing

Comments