[英]asp.net forms authentication occasionally redirects to default.aspx
Am using forms authentication along with the asp.net login controls in my website. 我在我的网站中使用表单身份验证以及asp.net登录控件。 Based on the roles i have to redirect my users to two different pages. 根据角色,我必须将我的用户重定向到两个不同的页面。
The code works but occasionally it takes me to either default.aspx which is not present and sometimes it simple refreshes my current login page. 该代码有效,但有时它需要我进入default.aspx(不存在),有时它会刷新我的当前登录页面。 Any help is appreciated. 任何帮助表示赞赏。
Here is my code behind 这是我的代码背后
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");
}
}
and following markup from web.config 然后从web.config标记
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx"
slidingExpiration="true"
cookieless="AutoDetect"
></forms>
</authentication>
You missed the default condition, what if none of the above IF condition holds true ? 您错过了默认条件,如果以上IF条件都不成立,该怎么办? That case it will just refresh the current page after post back. 在这种情况下,它只会在回发后刷新当前页面。
You forgot to mention code behind Login1_LoggedIn is on which page ? 您忘了在哪一页上提到Login1_LoggedIn背后的代码?
And What happens if The rolenames[0] is not and "Administrators" or "Employees"? 如果Rolenames [0]不是并且“ Administrators”或“ Employees”,会发生什么? Set a default condition and you should be good to go. 设置默认条件,您应该一切顺利。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.