views:

313

answers:

1

Hello, I have a .Net Login Control with a event handler for onloggedin.

onloggedin="Login2_LoggedIn"

However User.Identity is always null.

 protected void Login2_LoggedIn(object sender, EventArgs e)
{
    // Is User is Admin
    if (Roles.IsUserInRole(User.Identity.Name, "admin"))

Is it supposed to be available at this point? Or should I get the user name from the object sender or EventArgs e?

+2  A: 

Page.User is not available until the page posts back after authenticating, so it is null on the page hosting the login control. However, you can still call the method by using the UserName property of the login control. This is safe to do in the LoggedIn event handler because the user has been authenticated at this point.

if (Roles.IsUserInRole(Login2.UserName, "admin"))
...
Jamie Ide