HttpContext.Current.User not available in the redirected page

Discussion in 'ASP .Net Security' started by Ali Khawaja, Nov 1, 2003.

  1. Ali Khawaja

    Ali Khawaja Guest

    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
     
    Ali Khawaja, Nov 1, 2003
    #1
    1. Advertising

  2. Ali Khawaja

    MSFT Guest

    MSFT, Nov 3, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Newton
    Replies:
    0
    Views:
    2,950
    Mike Newton
    Jul 23, 2004
  2. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    1,660
    Steve C. Orr [MVP, MCSD]
    Jul 23, 2004
  3. nalbayo
    Replies:
    2
    Views:
    5,569
    Bruce Barker
    Nov 11, 2005
  4. Dwight Johnson

    HttpContext.Current.User returns old user id

    Dwight Johnson, Feb 16, 2010, in forum: ASP .Net
    Replies:
    1
    Views:
    1,307
    Alexey Smirnov
    Feb 28, 2010
  5. Tony

    Dim context As HttpContext = HttpContext.Current

    Tony, Mar 2, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    335
    Teemu Keiski
    Mar 3, 2004
Loading...

Share This Page