Problem with setauthcookie

From: David Colliver (anonymous_at_discussions.microsoft.com)
Date: 05/12/05

  • Next message: casper: "Custom authentication"
    Date: Thu, 12 May 2005 01:29:53 -0700
    
    

    Hi all,

    I am having a problem with setting the auth cookie.

    I have a username/password box on a page. In my button
    event, I am checking a database with the
    username/password pair and if I get a row returned, then
    I do...

    FormsAuthentication.SetAuthCookie(UserNameBox.Text, true);

    then do a little bit on my page, such as switching off
    panels and switching others on.

    Now, on one of the panels that I switch on, I have
    linkbuttons which post the page back. I am checking...

    if (User.Identity.IsAuthenticated) to do other
    operations. This is in my page_load, but IsAuthenticated
    is returning false.

    I know of no reason. Can anybody help?

    My code...

                    private void Page_Load(object sender,
    System.EventArgs e)
                    {
                            // Put user code to initialize
    the page here
                            //CheckLogin();
                            if (User.Identity.IsAuthenticated)
                            {
                                    TabListPanel.Visible =
    true;
                                    Trace.Warn("Auth",
    DateTime.Now.ToString());
                            }
                            else
                            {
                                    LoginPanel.Visible = true;
                            }
                    }

                    private void LoginButton_Click(object
    sender, System.EventArgs e)
                    {
                            CheckLogin();
                    }

                    private void CheckLogin()
                    {
                            try
                            {
                                    sqlConn.Open();

                                    SqlDataAdapter cmd;

                                    if
    (User.Identity.IsAuthenticated)
                                    {
                                            cmd = new
    SqlDataAdapter(MyNoneAuthSqlStatement, sqlConn);
                                    }
                                    else
                                    {
                                            cmd = new
    SqlDataAdapter(MyAuthSqlStatement, sqlConn);
                                    }

                                    DataSet Login = new
    DataSet();
                                    cmd.Fill
    (Login, "UserDetails");

                                    if (Login.Tables
    ["UserDetails"].Rows.Count > 0)
                                    {
                                            // Write the
    authentication cookie.
                                    
            FormsAuthentication.SetAuthCookie
    (LoginEmailTextBox.Text, true);
                                            // Remove login
    panel, show links (TAB) panel.
                                    
            LoginPanel.Visible = false;
                                    
            TabListPanel.Visible = true;
                                    }
                            }
                            finally
                            {
                                    sqlConn.Close();
                            }
                    }

    This is in my web.config... I have to be careful in here
    as this may have issues elsewhere on the site.

            <authentication mode="Forms">
            <forms loginUrl="MyLogonPage.aspx"
    name="adAuthCookie" timeout="60" path="/NQT">
            </forms>
            </authentication>

    Thanks for any assistance.

    Best regards,
    Dave Colliver.
    http://www.SheffieldFOCUS.com
    ~~
    http://www.FOCUSPortals.com - portal franchises available


  • Next message: casper: "Custom authentication"