Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Custom principal "replaced" by GenericPrincipal

Custom principal "replaced" by GenericPrincipal

Scheduled Pinned Locked Moved ASP.NET
helpquestioncsharpsecuritylearning
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EnkelIk
    wrote on last edited by
    #1

    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; /********************************/

    T 1 Reply Last reply
    0
    • E EnkelIk

      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; /********************************/

      T Offline
      T Offline
      Tim Nape
      wrote on last edited by
      #2

      Overridding Principal in: protected void Application_PostAuthenticateRequest(object sender, EventArgs e) Instead of protected void Application_AuthenticateRequest(object sender, EventArgs e) In Global.asax.cs worked for me in an ASP web application

      Tim

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups