How do I update FormsAuthenticationTicker.userdata after ticket created?

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default How do I update FormsAuthenticationTicker.userdata after ticket created?

    When a user logs on to an application the new FormsAuthenticationTicket is
    created with a userdata field which I can populate with anything useful I
    might want. A cookie is created with an encrypted hash of the ticket.

    Is it possible to update the ticket's userdata field once the ticket has
    been created or is the ticket strictly readonly? If this isn't possible then
    I expect I will just need to create my own cookie for additional information
    that needs to change.

    Thanks!
    Bill


    Wysiwyg Guest

  2. Similar Questions and Discussions

    1. UserData file issues
      In the process of setting up a multitude of sites, we are having issues with the _mm/ct3beta/messaging/users/list/UserData.<random_string>.csi.new...
    2. FormsAuthenticationTicket does not return userdata
      Hello, I am trying to get FormAuthentication working, but the FormsAuthenticationTicket does not return the UserData. Does any one have any...
    3. Manually created Cookie with UserData won't persist
      I'm manually creating a FormsAuthenticationTicket and adding userdata. The problem is that the cookie won't persist. Code:...
    4. How do you add userdata in maya?
      Does anyone know how to add userdata in Maya, I can't seem to find it in the documentation or on google? Thanks Tim
    5. Insert & Update triggers fire together when a new record is created.
      Hi, I have two triggers, one when an insert is performed and the other when an update is performed. I use these triggers to synchronize two...
  3. #2

    Default Re: How do I update FormsAuthenticationTicker.userdata after ticket created?

    In fact, the ticket is readonly. However, you may recreate it with your new
    Userdata value and update the forms cookie with the newly created ticket.
    Check out this code:

    // Get the cookie created by the FormsAuthentication API
    // If you put this code in Application_AuthenticateRequest
    // event, you may use Context.User.Identity.Name prop. instedad of
    UserId.Text
    HttpCookie cookie = FormsAuthentication.GetAuthCookie( UserId.Text,
    false );
    FormsAuthenticationTicket ticket =
    FormsAuthentication.Decrypt(cookie.Value);

    // Notice that all current ticket properties are preserved in the new
    ticket
    FormsAuthenticationTicket newticket = new FormsAuthenticationTicket(
    ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration,
    ticket.IsPersistent, yourNewUserDataValue, ticket.CookiePath);

    // add the encrypted ticket to the cookie as data.
    cookie.Value = FormsAuthentication.Encrypt(newticket);

    // Update the outgoing cookies collection.
    Context.Response.Cookies.Set(cookie);


    Hernan de Lahitte
    [url]http://weblogs.asp.net/hernandl[/url]


    "Wysiwyg" <wysiwyg@xmissionNSPAM.com> wrote in message
    news:cpaga9$5gb$1@news.xmission.com...
    > When a user logs on to an application the new FormsAuthenticationTicket is
    > created with a userdata field which I can populate with anything useful I
    > might want. A cookie is created with an encrypted hash of the ticket.
    >
    > Is it possible to update the ticket's userdata field once the ticket has
    > been created or is the ticket strictly readonly? If this isn't possible
    > then
    > I expect I will just need to create my own cookie for additional
    > information
    > that needs to change.
    >
    > Thanks!
    > Bill
    >
    >

    Hernan de Lahitte Guest

  4. #3

    Default Re: How do I update FormsAuthenticationTicker.userdata after ticket created?

    Thanks for the reply! Recreating the ticket is the way to go.

    Thanks again,

    Bill

    "Hernan de Lahitte" <hernan@lagash.com> wrote in message
    news:OfuiZYk3EHA.1392@tk2msftngp13.phx.gbl...
    > In fact, the ticket is readonly. However, you may recreate it with your
    new
    > Userdata value and update the forms cookie with the newly created ticket.
    > Check out this code:
    >
    > // Get the cookie created by the FormsAuthentication API
    > // If you put this code in Application_AuthenticateRequest
    > // event, you may use Context.User.Identity.Name prop. instedad of
    > UserId.Text
    > HttpCookie cookie = FormsAuthentication.GetAuthCookie( UserId.Text,
    > false );
    > FormsAuthenticationTicket ticket =
    > FormsAuthentication.Decrypt(cookie.Value);
    >
    > // Notice that all current ticket properties are preserved in the new
    > ticket
    > FormsAuthenticationTicket newticket = new FormsAuthenticationTicket(
    > ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration,
    > ticket.IsPersistent, yourNewUserDataValue, ticket.CookiePath);
    >
    > // add the encrypted ticket to the cookie as data.
    > cookie.Value = FormsAuthentication.Encrypt(newticket);
    >
    > // Update the outgoing cookies collection.
    > Context.Response.Cookies.Set(cookie);

    Wysiwyg Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139