gpt4 book ai didi

asp.net - 使用 Web.Config 进行 Asp.net 表单例份验证登录后重定向不起作用

转载 作者:行者123 更新时间:2023-12-01 12:50:09 25 4
gpt4 key购买 nike

我正在尝试通过将用户名和密码存储在 web.config 文件中来登录,如下所示

 <authentication mode="Forms">
<forms loginUrl="Admin Login.aspx" defaultUrl="~/Home.aspx">
<credentials>
<user name="Admin" password="123" />

</credentials>
</forms>
</authentication>

我在提交按钮上写了这段代码

 if (FormsAuthentication.Authenticate(TxtUsername.Text, TxtPassword.Text))
{

Response.Redirect(FormsAuthentication.GetRedirectUrl(TxtUsername.Text, false));
}

但它没有被重定向..有什么建议吗..?

最佳答案

您需要调用FormsAuthentication.SetAuthCookie()在重定向之前。

if (FormsAuthentication.Authenticate(TxtUsername.Text, TxtPassword.Text))
{
FormsAuthentication.SetAuthCookie(TxtUsername.Text, false);
Response.Redirect(FormsAuthentication.GetRedirectUrl(TxtUsername.Text, false));
}

关于asp.net - 使用 Web.Config 进行 Asp.net 表单例份验证登录后重定向不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13062081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com