views:

103

answers:

1

In which part of the Global.asax lifecycle can I safely 'use' the User object? I'm using the default forms authentication and noticed the following:

Sub Application_BeginRequest()
    'Context.User Is Nothing
End Sub

Sub Application_AuthenticateRequest()
    'Context.User Is Nothing
End Sub

Sub Application_AuthorizeRequest()
    'Context.User is available
    'Context.User.IsInRole() returns false while user is in role
End Sub

Seems like AuthorizeRequest() should be the place, however IsInRole() doesn't return the expected true. Am I missing something here?

+2  A: 

I think you actually want to do it in Post_AuthenticateRequest:

void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e)
{
    // Context.User is available now, and IsInRole() should work fine;
}
ckramer
pre: I **validate ASP.NET configuration** (username,isinrole, roles setup "admin") 0. I run in debug mode 1. I **logout/login** using 'username' 2. I execute an action which checks **IsInRole("admin")**It returns `false`. **Are roles and everything setup?**
Ropstah