forms authentication question

Z

z. f.

Hi,

i use Forms authentication in my vb.net asp web application
on the login page i set the authentication cookie, and i can see the cookie
is there.
on the Global_AuthenticateRequest
i get the IsNothing(HttpContext.Current.User) = true
why the framework don't recognise my cookie?

the code to put the cookie is:

FormsAuthentication.Initialize()

Dim ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket( _

1, userId, _

DateTime.Now, DateTime.Now.AddMinutes(Session.Timeout), _

False, roles)

Dim hash As String = FormsAuthentication.Encrypt(ticket)

Dim cookie As HttpCookie = New
HttpCookie(FormsAuthentication.FormsCookieName, hash)

' Add the cookie to the list for outgoing response

Page.Response.Cookies.Add(cookie)
 
H

Hernan de Lahitte

You may use a "safer" approach for building Forms cookies from this sample :
http://weblogs.asp.net/hernandl/archive/2004/08/05/FormsAuthRoles2.aspx

Notice the first line:

// Get the cookie created by the FormsAuthentication API
// Notice that this cookie will have all the attributes according to
// the ones in the config file setting.
HttpCookie cookie = FormsAuthentication.GetAuthCookie( userId, false );

And the cookie updating code:

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

--
Hernan de Lahitte
http://weblogs.asp.net/hernandl

"z. f." <[email protected]> escribi? en el mensaje
Hi,

i use Forms authentication in my vb.net asp web application
on the login page i set the authentication cookie, and i can see the cookie
is there.
on the Global_AuthenticateRequest
i get the IsNothing(HttpContext.Current.User) = true
why the framework don't recognise my cookie?

the code to put the cookie is:

FormsAuthentication.Initialize()

Dim ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket( _

1, userId, _

DateTime.Now, DateTime.Now.AddMinutes(Session.Timeout), _

False, roles)

Dim hash As String = FormsAuthentication.Encrypt(ticket)

Dim cookie As HttpCookie = New
HttpCookie(FormsAuthentication.FormsCookieName, hash)

' Add the cookie to the list for outgoing response

Page.Response.Cookies.Add(cookie)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top