determining if a user is authenticated

  • Thread starter Thread starter Robert Rotstein
  • Start date Start date
R

Robert Rotstein

How does one determine from Global.Application_BeginRequest() -- where
no Session information is available -- whether the invoking user has
been authenticated?
 
The application events occur in this sequence: BeginRequest,
AuthenticateRequest, AuthorizeRequest. Therefore you can determine if the
user was authenticated only starting at the AuthenticateRequest event
handling, e.g.

Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As
EventArgs)
Dim app As HttpApplication = CType(sender, HttpApplication)
If app.Context.User.Identity.IsAuthenticated Then
'do something
End If
End Sub
 
You don't. There no access to Session from
that event, as you have already found out.

SessionState is not loaded until after the BeginRequest
has fired and before the EndRequest has fired.

Specifically, Session is accessible after AcquireRequestState has fired :

http://msdn.microsoft.com/library/d...papplicationclassacquirerequeststatetopic.asp

You might want to use any event which fires after AcquireRequestState
has fired, like HttpApplication.PreRequestHandlerExecute :

http://msdn.microsoft.com/library/d...papplicationclassacquirerequeststatetopic.asp

You could also use the PreSendRequestContent event :
http://msdn.microsoft.com/library/d...pplicationClassPreSendRequestContentTopic.asp



Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
 

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

Back
Top