如何使用asp.net成员身份验证重定向页面 [英] how to redirect a page using asp.net membership authentication
问题描述
Hello.i我正在使用asp.net身份验证来验证我的应用程序中的用户。当我输入用户名和密码并调试代码时,我可以看到 Page.User.Identity.IsAuthenticated 是假的,然后登录并在用户登录的同时显示登录页面
。当我在同一窗口中再次登录时,它会在Page.User.Identity时登录.IsAuthenticated返回true。每次第一次返回false,但是当我再次登录时,它会影响到。我怎么能解决这个错误?
以下是我的代码
受保护 void Login1_LoggingIn( object sender,LoginCancelEventArgs e)
{
MembershipUser user = Membership.GetUser(Login1.UserName);
if (Page.User.Identity.IsAuthenticated)
{
if (Page.User.Identity.IsAuthenticated)
{
if (Request.QueryString [ ReturnUrl]!= null )
{
Login1.DestinationPageUrl = Request.QueryString [ ReturnUrl]。ToString( );
}
if (Roles.IsUserInRole( Admin))
{
Response.Redirect( 〜/ Adminstrator / Admin.aspx);
}
if (Roles.IsUserInRole( 其他))
{
Response.Redirect( 〜/ Others / Registrations.aspx);
}
}
}
}
在调试时它首先检查那些角色/条件,只有当我再次输入详细信息时它才会再次检查,任何一个有解决方案?
谢谢
这可能会有所帮助: User.Identity.IsAuthenticated仍为false。为什么? [ ^ ]
Hello.i am using asp.net authentication to validate a user in my application.When i enter the username and password and debug the code,i can see that the Page.User.Identity.IsAuthenticated is false,it then logs in and shows login page at the same time the user is logged in
.When i log in again while still in the same window ,its then when Page.User.Identity.IsAuthenticated returns true .Every first time it returns false but when i log in again,it effects that.How can i solve this error?
below is my code
protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
{
MembershipUser user = Membership.GetUser(Login1.UserName);
if (Page.User.Identity.IsAuthenticated)
{
if (Page.User.Identity.IsAuthenticated)
{
if (Request.QueryString["ReturnUrl"] != null)
{
Login1.DestinationPageUrl = Request.QueryString["ReturnUrl"].ToString();
}
if (Roles.IsUserInRole("Admin"))
{
Response.Redirect("~/Adminstrator/Admin.aspx");
}
if (Roles.IsUserInRole("Others"))
{
Response.Redirect("~/Others/Registrations.aspx");
}
}
}
}
On debugging it doesnt at first check those roles/conditions,,only when i enter the details again it will come checking again,Any one with a solution?
Thanks
This may help: User.Identity.IsAuthenticated remains false. why?[^]
这篇关于如何使用asp.net成员身份验证重定向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!