Custom principal "replaced" by GenericPrincipal
-
Hi all! I just converted a .net 1.1 web project to .net 2.0 and now I'm getting a strange problem: I have a custom class implementing IPrincipal to store the user identity in Context.User, sample code below. After storing the Principal i redirect from the login-page. When I retrieve the Context.User on the next page it is of type GenericPrincipal????? The user information is still there but of course not with my custom methods. I guess I could rewrite the code to use GenericPrinfipal instead, but why does this happen??? It did not happen before the conversion (and as far as I can think of I didn't make any other changes to the code). I use Forms-authentication (using Windows authentication gives me the WindowsPrincipal when retrieving Context.User - i.e. the useridentity of the useraccount running the app, not of the user logged in to the web app). I feel there has to be a logical explanation for this and I am grateful for any help! Thanks! /*******************************/ CustPrincipal newUser = CustPrincipal.ValidateLogin(TxtUsername.Text, TxtPassword.Text); // Create the authentication ticket FormsAuthenticationTicket authTicket = newUser.GetAuthenticationTicket(); // Now encrypt the ticket. string encryptedTicket = FormsAuthentication.Encrypt(authTicket); // Create a cookie and add the encrypted ticket to the // cookie as data. HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); // Add the cookie to the outgoing cookies collection. Response.Cookies.Add(authCookie); // Add user to context Context.User = newUser; System.Threading.Thread.CurrentPrincipal = newUser; /********************************/
-
Hi all! I just converted a .net 1.1 web project to .net 2.0 and now I'm getting a strange problem: I have a custom class implementing IPrincipal to store the user identity in Context.User, sample code below. After storing the Principal i redirect from the login-page. When I retrieve the Context.User on the next page it is of type GenericPrincipal????? The user information is still there but of course not with my custom methods. I guess I could rewrite the code to use GenericPrinfipal instead, but why does this happen??? It did not happen before the conversion (and as far as I can think of I didn't make any other changes to the code). I use Forms-authentication (using Windows authentication gives me the WindowsPrincipal when retrieving Context.User - i.e. the useridentity of the useraccount running the app, not of the user logged in to the web app). I feel there has to be a logical explanation for this and I am grateful for any help! Thanks! /*******************************/ CustPrincipal newUser = CustPrincipal.ValidateLogin(TxtUsername.Text, TxtPassword.Text); // Create the authentication ticket FormsAuthenticationTicket authTicket = newUser.GetAuthenticationTicket(); // Now encrypt the ticket. string encryptedTicket = FormsAuthentication.Encrypt(authTicket); // Create a cookie and add the encrypted ticket to the // cookie as data. HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); // Add the cookie to the outgoing cookies collection. Response.Cookies.Add(authCookie); // Add user to context Context.User = newUser; System.Threading.Thread.CurrentPrincipal = newUser; /********************************/