asp.net表单身份验证偶尔会重定向到default.aspx
本文关键字:重定向 default aspx 偶尔 net 表单 身份验证 asp | 更新日期: 2023-09-27 18:21:17
我在网站中使用表单身份验证和asp.net登录控件。根据角色,我必须将我的用户重定向到两个不同的页面。
代码很有效,但偶尔我会转到不存在的default.aspx,有时它只是刷新我当前的登录页面。感谢您的帮助。
这是后面的代码
protected void Login1_LoggedIn(object sender, EventArgs e)
{
string[] rolenames = System.Web.Security.Roles.GetRolesForUser(User.Identity.Name);
if (rolenames.Length > 0)
{
if (rolenames[0] == "Administrators")
Response.Redirect("~/Administrators/Home.aspx");
else if (rolenames[0] == "Employees")
Response.Redirect("~/Employees/Home.aspx");
}
}
以及web.config 中的以下标记
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx"
slidingExpiration="true"
cookieless="AutoDetect"
></forms>
</authentication>
您错过了默认条件,如果以上if条件都不成立怎么办?在这种情况下,它只会在发布后刷新当前页面。
您忘记提到Login1_LoggedIn在哪个页面上的代码?
如果角色名称[0]不是"Administrators"或"Employees",会发生什么?设置一个默认条件,你就可以开始了。