开发者

Forms authentication issue

<authentication mode="Forms">
        <forms loginUrl="LoginPage.aspx"
           protection="All"
           timeout="1"
           name=".ASPXAUTH"
           path="/"
           requireSSL="false"
           slidingExpiration="false"
           defaultUrl="HomePage.aspx"
           cookieless="UseDeviceProfile"
           enableCrossAppRedirects="false"/>
      </authentication>

protected void btnSubmit_Click(object sender, EventArgs e)
        {
    开发者_运维技巧       int recordExistCount = fc.Authenticate(txtUsername.Text.Trim(), txtPassword.Text.Trim());
           if (recordExistCount == 1)
           {
               Session["User"] = "Authenticated";
               Session["Username"] = txtUsername.Text.Trim();
               fc.IsOnlineRecord(Session["Username"].ToString(),true);
               FormsAuthentication.RedirectFromLoginPage(Session["Username"].ToString(), true);
           Response.Redirect("HomePage.aspx");
           }
           else
           {
               lblStatus.Text = "Username or password specified are incorrect";
               lblStatus.BackColor = Color.Yellow;               
           }
        }

Forms authentication doesnt work properly. After one successfull login , I go to the website url and it doesnt go to Homepage and instead takes me again to the loginpage. What am I doing wrong?


Increase the timeout. 1 minute is incredibly low. I believe 20 minutes is the default. Also, set slidingexpiration to true otherwise every user will have to re-authenticate at 1 minute.


It seems as though you are not setting the Formsauthentication. Therefore, in the code behind of the LoginPage.aspx - on the login click event try something like this

protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                //get the user details and authenticate them against whatever means you need to
                FormsAuthentication.RedirectFromLoginPage(authenticatedUser.Email, false);
                Response.Redirect("~/HomePage.aspx");
            }
            catch
            {
                //catch any errors here
            }
        }


How you are performing the login? Is it with the login control or are you doing it manually?

If you're doing it manually run your app through fiddler and see if the .ASPAUTH cookie is being created and dropped. Increase the timeout from a minute. Post your manual code so we can see how you're creating the token.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜