D
David C. Taylor
I have an application using FormsAuthentication that does
not persist the authentication cookie beyond the session
so each time a user starts a session they must go through
the login page. On this login page I set a couple of
session variables while I am making the database trip for
authentication. This all works fine without any problems.
Now, I have the requirement to provide an option for a
user to 'Remember Me' using a checkbox and persisting the
cookie. The result is that users that take this option
will bypass the login page and the setting of the
necessary session variables. I decided to write the data
to the cookie as the FormsAuthenticationTicket.UserData
property and then retrieve it. I am using the MSDN
documentation for that property and the example shows how
to retrieve that value using this code in VB.Net:
Dim id As FormsIdentity = CType(User.Identity,
FormsIdentity)
Dim ticket As FormsAuthenticationTicket = id.Ticket
userData.Text = ticket.UserData
However, when I run this code I get an Invalid Cast
Exception on the first line.
I need to know how to make this type conversion work, why
it is not working, or just a workaround for this issue.
Thanks for any help,
David C. Taylor, MCP
not persist the authentication cookie beyond the session
so each time a user starts a session they must go through
the login page. On this login page I set a couple of
session variables while I am making the database trip for
authentication. This all works fine without any problems.
Now, I have the requirement to provide an option for a
user to 'Remember Me' using a checkbox and persisting the
cookie. The result is that users that take this option
will bypass the login page and the setting of the
necessary session variables. I decided to write the data
to the cookie as the FormsAuthenticationTicket.UserData
property and then retrieve it. I am using the MSDN
documentation for that property and the example shows how
to retrieve that value using this code in VB.Net:
Dim id As FormsIdentity = CType(User.Identity,
FormsIdentity)
Dim ticket As FormsAuthenticationTicket = id.Ticket
userData.Text = ticket.UserData
However, when I run this code I get an Invalid Cast
Exception on the first line.
I need to know how to make this type conversion work, why
it is not working, or just a workaround for this issue.
Thanks for any help,
David C. Taylor, MCP