Context.User.IsAuthenticated = false?????

Discussion in 'ASP .Net Security' started by James Coleman, Apr 10, 2006.

  1. I have a asp:Login control with an OnLoggedIn="Login1_LoggedIn" method.

    The first time through the method the Context.User.IsAuthenticated = false.
    The 2nd time I log in, it is then true. Anyone know why this is, am I doing
    something wrong, is there a way around it?

    protected void Login1_LoggedIn(object sender, EventArgs e)
    {
    Login myLogin = sender as Login;

    // if we get a Ticket from AuthenticateAsUser the credentials are
    valid
    //Ticket =
    CmsFormsAuthentication.AuthenticateAsUser(Login1.UserName, Login1.Password);
    if (Context.User.IsInRole("Admin"))
    {
    //Ticket =
    CmsFormsAuthentication.AuthenticateAsUser("WinNT://webacom/jcoleman",
    "`1q`1q");
    Ticket = CmsFormsAuthentication.AuthenticateAsUser("WinNT://" +
    WebConfigurationManager.AppSettings["ADMIN_USERNAME"],
    WebConfigurationManager.AppSettings["ADMIN_PASSWORD"]);
    }
    else if (Context.User.IsInRole("Dealer"))
    {
    Ticket = CmsFormsAuthentication.AuthenticateAsUser("WinNT://" +
    WebConfigurationManager.AppSettings["DEALER_USERNAME"],
    WebConfigurationManager.AppSettings["DEALER_PASSWORD"]);
    }
    else
    {
    CmsFormsAuthentication.AuthenticateAsGuest();
    }
    if (Ticket != null)
    {
    CmsFormsAuthentication.SetAuthCookie(Ticket, false,
    Login1.RememberMeSet);
    }
    }

    Thanks
    ~James
    --
    James Coleman
    Technical Director
    AGENCY.COM [Chicago]
    James Coleman, Apr 10, 2006
    #1
    1. Advertising

  2. to be "authenticated" you need an extra roundtrip to the client to set the
    authentication ticket.

    thats why you see this behavior.

    ---------------------------------------
    Dominick Baier - DevelopMentor
    http://www.leastprivilege.com

    > I have a asp:Login control with an OnLoggedIn="Login1_LoggedIn"
    > method.
    >
    > The first time through the method the Context.User.IsAuthenticated =
    > false. The 2nd time I log in, it is then true. Anyone know why this
    > is, am I doing something wrong, is there a way around it?
    >
    > protected void Login1_LoggedIn(object sender, EventArgs e)
    > {
    > Login myLogin = sender as Login;
    > // if we get a Ticket from AuthenticateAsUser the credentials
    > are
    > valid
    > //Ticket =
    > CmsFormsAuthentication.AuthenticateAsUser(Login1.UserName,
    > Login1.Password);
    > if (Context.User.IsInRole("Admin"))
    > {
    > //Ticket =
    > CmsFormsAuthentication.AuthenticateAsUser("WinNT://webacom/jcoleman",
    > "`1q`1q");
    > Ticket =
    > CmsFormsAuthentication.AuthenticateAsUser("WinNT://" +
    > WebConfigurationManager.AppSettings["ADMIN_USERNAME"],
    > WebConfigurationManager.AppSettings["ADMIN_PASSWORD"]);
    > }
    > else if (Context.User.IsInRole("Dealer"))
    > {
    > Ticket =
    > CmsFormsAuthentication.AuthenticateAsUser("WinNT://" +
    > WebConfigurationManager.AppSettings["DEALER_USERNAME"],
    > WebConfigurationManager.AppSettings["DEALER_PASSWORD"]);
    > }
    > else
    > {
    > CmsFormsAuthentication.AuthenticateAsGuest();
    > }
    > if (Ticket != null)
    > {
    > CmsFormsAuthentication.SetAuthCookie(Ticket, false,
    > Login1.RememberMeSet);
    > }
    > }
    > Thanks
    > ~James
    Dominick Baier [DevelopMentor], Apr 11, 2006
    #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. Nick
    Replies:
    0
    Views:
    573
  2. Bob
    Replies:
    1
    Views:
    11,906
    Joe Fallon
    Apr 29, 2004
  3. ChInKPoInt [No MCSD]
    Replies:
    0
    Views:
    787
    ChInKPoInt [No MCSD]
    Dec 4, 2004
  4. Pascal
    Replies:
    0
    Views:
    466
    Pascal
    Aug 31, 2005
  5. taylomic
    Replies:
    0
    Views:
    1,804
    taylomic
    Dec 19, 2008
Loading...

Share This Page