2016-03-05 138 views
0

当我在asp.net的登录页面输入用户名和密码,并且在检查用户没有重定向到管理页面后。ASP.NET不重定向到管理页面

这是我的代码:

if (Page.IsValid) 
{ 
     if (Page.User.Identity.IsAuthenticated) 
     { 
      Response.Redirect("~/ManagePage/Default.aspx"); 
     } 
     else 
     { 
      if (CheckLogin(UserName.Text.Trim(), Password.Text.Trim()) == true) 
      { 
       FormsAuthentication.RedirectFromLoginPage(UserName.Text.Trim(), false); 

       if (Roles.GetRolesForUser(UserName.Text.Trim())[0] == "Admin") 
       { 
        Session["CounterLogin"] = 0; 
        Response.Redirect("~/ManagePage/Default.aspx"); 
       } 
       else if (Roles.GetRolesForUser(UserName.Text)[0] == "User") 
       { 
        Session["CounterLogin"] = 0; 
        Response.Redirect("~/Default.aspx"); 
       } 
      } 
      else 
      { 
       FailureText.Text = "Please Check UserName And Password"; 
      } 
     } 
} 

我使用在其他项目中该代码的作品,但在我的新项目这是行不通的。

回答

0

尝试进行登陆期运用FormsAuthentication.SetAuthCookie:

FormsAuthentication.SetAuthCookie(UserName.Text.Trim(), false); 

,并检查启用FormsAuthentication在web.config中

<authentication mode="Forms"> 
    <forms loginUrl="~/Home/Login" > 
    </forms> 
</authentication> 

+0

我尝试这种解决方案,但不到风度解决... – ASO

+0

它再次返回到登录页面 – ASO