Custom Principle Object and storing between postbacks - Tickets?

Last post 05-20-2008 5:41 AM by vdh_ant. 9 replies.

Sort Posts:

  • Custom Principle Object and storing between postbacks - Tickets?

    05-17-2008, 8:56 AM
    • Member
      point Member
    • vdh_ant
    • Member since 08-04-2007, 9:13 AM
    • Posts 56
    Hi guys
    I have created my own Principle and Identity classes and it seems to be going well. The only thing that is a real pain though is that the Principle object is not being stored automatically between postbacks like the default principle object is. At the moment I am manually storing the Principle object in the session and putting it into HttpContext.Current.User in the Application_AcquireRequestState event. But i am thinking that this is not the best way to do this.

    I am guessing that this has something to do with Forms Authentication Tickets and Cookies, but I am a bit hazy on how to get it so that my class gets stored between postbacks.

    Hence i was just wondering if anyone knows what i need to do to get this to work.
    Cheers
    Anthony
  • Re: Custom Principle Object and storing between postbacks - Tickets?

    05-18-2008, 2:01 AM
    • Member
      point Member
    • vdh_ant
    • Member since 08-04-2007, 9:13 AM
    • Posts 56

    Anyone got any ideas

  • Re: Custom Principle Object and storing between postbacks - Tickets?

    05-18-2008, 3:25 AM
    Answer
    • All-Star
      60,921 point All-Star
    • anas
    • Member since 09-21-2006, 8:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,865
    • Moderator

    One solution is to create a base page , so that all pages inherits from ,

    then in the base page load function , you can check the Current user Principal type , if its not like your custom principal type,  you set it to your custom principal,

     

          If Context.User.Identity.IsAuthenticated Then
    ' check to see if the current principal is not like your principal type
    If Not (TypeOf context.User Is YourPrincipal) Then

    Dim
    newUser As New YourPrincipal(.....
    Context.User = newUser

    End If

    End If

     

    Another solution is to check that in Application_AuthenticateRequest ( from global application class , or custom HttpModule) 

    Regards,

    Anas Ghanem | Blog

  • Re: Custom Principle Object and storing between postbacks - Tickets?

    05-18-2008, 5:39 AM
    • Member
      point Member
    • vdh_ant
    • Member since 08-04-2007, 9:13 AM
    • Posts 56

    In terms of storing the information between postbacks though (i.e. the roles that the user has) i dont see how this helps.

    At the moment i am storing it in the session and setting it. Are you surgesting that i should regather this data every time the Application_AuthenticateRequest runs (as this is where I would put it)?

  • Re: Custom Principle Object and storing between postbacks - Tickets?

    05-19-2008, 6:31 AM

    Hi

    I've written a example about how to serialize and store information in FormsauthenticationTicket.UserData in this thread for your reference.

    http://forums.asp.net/p/1253732/2324459.aspx 

    If the above answer hasn't answered your question, please provide more info. Thanks

    Best Regards
    XiaoYong Dai
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: Custom Principle Object and storing between postbacks - Tickets?

    05-20-2008, 1:48 AM
    • Member
      point Member
    • vdh_ant
    • Member since 08-04-2007, 9:13 AM
    • Posts 56

    Thanks for the information this is great.

    Just one question though. Now that I think about it how advisable is it to store the role information on the client. I know its encrypted and everything but something makes me think twice about this.

    Any thoughts???

    Cheers
    Anthony

  • Re: Custom Principle Object and storing between postbacks - Tickets?

    05-20-2008, 2:41 AM

    Hi

    MachineKey is a secure, cryptographically random key for user to encrypt and decrypt data that want to keep secret, it's strong enough to a public website. However, if you want some additional protection, Secure Sockets Layer (SSL) will be a better choice.

    Best Regards
    XiaoYong Dai
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: Custom Principle Object and storing between postbacks - Tickets?

    05-20-2008, 3:09 AM
    • Member
      point Member
    • vdh_ant
    • Member since 08-04-2007, 9:13 AM
    • Posts 56

    Thanks for this 
    Do you or any one you know use this method in a public facing business app?

    In your opinion how great do you thing the risk is and at what point would you witch to not storing it on the client?

    Cheers
    Anthony

  • Re: Custom Principle Object and storing between postbacks - Tickets?

    05-20-2008, 5:24 AM
    Answer

    vdh_ant:
    Do you or any one you know use this method in a public facing business app?

    As far as I know, there are more and more website using the ASP.NET 2.0 technique, such as

    http://www.getvitalized.com/login.aspx

    vdh_ant:
    In your opinion how great do you thing the risk is and at what point would you witch to not storing it on the client?

    It's a theoretical possibility, So I suppose it will be strong enough to a public website. We have to store cookie in client and send to server for each request since HTTP is a disconnected, stateless protocol.

    Best Regards
    XiaoYong Dai
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: Custom Principle Object and storing between postbacks - Tickets?

    05-20-2008, 5:41 AM
    • Member
      point Member
    • vdh_ant
    • Member since 08-04-2007, 9:13 AM
    • Posts 56

    Cheers

Page 1 of 1 (10 items)