determining if a user is authenticated

R

Robert Rotstein

How does one determine from Global.Application_BeginRequest() -- where
no Session information is available -- whether the invoking user has
been authenticated?
 
G

Guest

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
 
J

Juan T. Llibre

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
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top