HttpContext.Current.User not available in the redirected page

A

Ali Khawaja

I am trying to use Forms Authentication and Role-Based Security:
I have two pages: login.aspx and Default.aspx.
--------------------------
This is what I have in the submit event handler of my login.aspx (it has
an id and pwd fields):

UserDAL user = new UserDAL();
if( user.Authenticate(id,pwd))
{
HttpContext.Current.User = new GenericPrincipal(User.Identity,
user.GetUserRoles(id));
FormsAuthentication.RedirectFromLoginPage(id,false);
}
--------------------------------
Everything works fine uptil here. User is authenticated, and Gets the
proper roles from the db.

The problem is when I redirect to Default.aspx.
I have the following code in the page_load event handler:

private void Page_Load(object sender, System.EventArgs e)
{
string userId = Context.User.Identity.Name;
if(User.IsInRole("SR"))
DisplayAuthorizedLinks(AccessLevel.SR_ALLOWED);
else if(User.IsInRole("CR"))
DisplayAuthorizedLinks(AccessLevel.CR_ALLOWED);
else if(User.IsInRole("FULL"))
DisplayAuthorizedLinks(AccessLevel.FULL_ACCESS);
else if(User.IsInRole("ADMIN"))
DisplayAuthorizedLinks(AccessLevel.ADMIN_ACCESS);
}

At this point, User roles are complete empty. I Can't figure out what is
the case. Seems like context is not being transferred to the other page.

I'll appreciate any help.
Thanks
Ali
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top