Asp.net 表单身份验证问题 受保护的void btnsupmit\u单击(对象发送者,事件参数e) { int recordExistCount=fc.Authenticate(txtserName.Text.Trim(),txtPassword.Text.Trim()); 如果(recordExistCount==1) { 会话[“用户”]=“已验证”; 会话[“用户名”]=txtUsername.Text.Trim(); fc.IsOnlineRecord(会话[“用户名”].ToString(),true); FormsAuthentication.RedirectFromLoginPage(会话[“用户名”].ToString(),true); 重定向(“HomePage.aspx”); } 其他的 { lblStatus.Text=“指定的用户名或密码不正确”; lblStatus.BackColor=Color.Yellow; } }

Asp.net 表单身份验证问题 受保护的void btnsupmit\u单击(对象发送者,事件参数e) { int recordExistCount=fc.Authenticate(txtserName.Text.Trim(),txtPassword.Text.Trim()); 如果(recordExistCount==1) { 会话[“用户”]=“已验证”; 会话[“用户名”]=txtUsername.Text.Trim(); fc.IsOnlineRecord(会话[“用户名”].ToString(),true); FormsAuthentication.RedirectFromLoginPage(会话[“用户名”].ToString(),true); 重定向(“HomePage.aspx”); } 其他的 { lblStatus.Text=“指定的用户名或密码不正确”; lblStatus.BackColor=Color.Yellow; } },asp.net,Asp.net,表单身份验证无法正常工作。在一次成功登录后,我转到网站url,它不会转到主页,而是再次转到登录页面。 我做错了什么?似乎您没有设置表单身份验证。因此,在LoginPage.aspx的代码隐藏中-在login click事件上,尝试以下操作 <authentication mode="Forms"> <forms loginUrl="LoginPage.aspx" protection="All" timeout="1"

表单身份验证无法正常工作。在一次成功登录后,我转到网站url,它不会转到主页,而是再次转到登录页面。
我做错了什么?

似乎您没有设置表单身份验证。因此,在LoginPage.aspx的代码隐藏中-在login click事件上,尝试以下操作

<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;               
           }
        }

您是如何执行登录的?是使用登录控件还是手动操作


如果您正在手动执行此操作,请通过fiddler运行应用程序,查看是否正在创建和删除.ASPAUTH cookie。将超时时间从1分钟增加到1分钟。发布您的手动代码,以便我们查看您如何创建令牌。

增加超时时间。1分钟是难以置信的低。我认为20分钟是默认时间。另外,将slidingexpiration设置为true,否则每个用户都必须在1分钟后重新进行身份验证

您的登录机制的代码是什么?您在LoginPage.aspx的代码背后做什么?formsauthentication类没有任何内容。这只是登录页面上的凭证检查,成功登录后会重定向到homepage.aspxI使用代码隐藏文件编辑问题。我错过了什么?不,伙计,没用。我已经在代码隐藏文件中添加了代码。您还需要查看@blowdart关于超时的回答。现在,我将超时时间增加到10分钟。但它仍然会进入登录页面。我真的不知道ASPAUTH到底是怎么回事我们可以开始聊天了吗?
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
            }
        }