登录asp.net表单身份验证后,请勿重定向到管理页面

时间:2015-11-28 12:26:30

标签: asp.net login web-config

在我的asp.net Web应用程序中,我正在使用具有以下配置的asp.net表单身份验证。

<authentication mode="Forms">
  <forms defaultUrl="~/ManagePage/Default.aspx" loginUrl="~/Account/Login.aspx" slidingExpiration="true" timeout="2880"></forms>
</authentication>

<roleManager enabled ="true" defaultProvider ="MyRoleProvider">
  <providers>
    <clear />
    <add name="MyRoleProvider" type="MyRoleProvider" connectionStringName="dbTaxiRaniConnectionString" applicationName="/" />
  </providers>
</roleManager>

这是登录按钮代码:

if (Page.IsValid)
    {
        if (Page.User.Identity.IsAuthenticated)
        {
            Alert.Show("Your Loged in ");
        }
        else
        {
            if (CheckLogin(UserName.Text.Trim(), Password.Text.Trim()) == true)
            {
                FormsAuthentication.SetAuthCookie(UserName.Text.Trim(), RememberMe.Checked);

                if (Roles.GetRolesForUser(UserName.Text.Trim())[0] == "Admin")
                {
                    Session["CounterLogin"] = 0;
                    Response.Redirect("../ManagePage/Default.aspx");

                }
                else if (Roles.GetRolesForUser(UserName.Text)[0] == "Suport")
                {
                    Session["CounterLogin"] = 0;
                    Response.Redirect("../ManagePage/Default.aspx");

                }
            }
            else
            {
                int i = (int)Session["CounterLogin"];
                Session["CounterLogin"] = i + 1;

                i = (int)Session["CounterLogin"];

                if (i > 3)
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
        }

    }

这是web.config代码包含在admin文件夹中:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <authorization>
      <deny roles="member"/>
      <allow roles="Admin,Suport" />
      <deny users="*"/>
    </authorization>
  </system.web>
</configuration>

点击登录按钮后用户登录工作为true但不重定向到~/ManagePage/Default.aspx并再次显示登录页面。可以解决这个问题吗?

0 个答案:

没有答案