简体   繁体   English

asp.net表单身份验证有时会重定向到default.aspx

[英]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.

相关问题 Asp.Net表单身份验证重定向到…/ myapp / default.aspx而不是…/ myapp / - Asp.Net forms authentication redirects to …/myapp/default.aspx instead of …/myapp/ ASP.NET登录自动重定向到Default.aspx - ASP.NET Login Auto Redirects to Default.aspx ASP.NET Default.aspx - ASP.NET Default.aspx ASP.NET Forms应用程序偶尔显示空白的“ default.aspx”页面,而不是加载/显示内容 - ASP.NET Forms application displays blank “default.aspx” page sporadically instead of loading/showing contents 如何从ASP.NET Web窗体迁移到ASP.NET网页? 即/default.aspx到/ default - How to migrate from ASP.NET Web Forms to ASP.NET Web Pages? i.e /default.aspx to /default default.aspx页面中的事件问题(ASP.net 3.5) - Problem with events in default.aspx page (ASP.net 3.5) 如何使用登录控件登录,并且登录后进入asp.net中的myPage.aspx而不是Default.aspx? - How to login with login control and when logged in go to myPage.aspx not Default.aspx in asp.net? 超时后,表单身份验证loginURL不会重定向到根Default.aspx - Forms Authentication loginURL not redirecting to root Default.aspx after timeout asp.Net C#site.Master-排除Default.aspx页? - asp.Net C# site.Master - Exclude Default.aspx page? ASP.NET C#-在default.aspx中显示正确的contentplaceholder - ASP.NET C# - Showing right contentplaceholder in default.aspx
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM