它让我在短时间内出局,ASP.NET登录

时间:2012-01-01 17:06:26

标签: asp.net

我为用户写了一个登录菜单和控制面板, 但在短时间内它会把我带出去,看看代码 你知道在配置文件中我写道“Admin”文件夹是安全的,它的超时时间是30分钟但是当我在40-50秒内登录时它会带我出去,我错在哪里? 请帮我 Web.config代码:

<authentication mode="Forms">
          <forms name="MyAppCookie" path="/" loginUrl="Login.aspx" protection="All" timeout="60" defaultUrl="Admin" />
      </authentication>
      <authorization>
          <allow users="*" />
      </authorization>
    <customErrors mode="Off" />
    <pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode="Never" enableViewStateMac="false" />
      <!--<sessionState timeout="1440"></sessionState>-->
  </system.web>
    <location path="Admin">
        <system.web>
            <authorization>
                <deny users="?" />
                <deny users="Users" />
            </authorization>
        </system.web>
    </location>

登录菜单:

var login = (from u in DataContext.Context.Core_Users
                         where u.UserName == txtuid.Text && u.Password == txtPwd.Text
                         select u).FirstOrDefault();
            if(login != null)
            {
                var role = (from r in DataContext.Context.Core_Roles
                            where r.RoleID == login.RoleID
                            select r).FirstOrDefault();
                if(role != null)
                {
                    string RoleName = role.RoleName;
                    FormsAuthenticationTicket AuthTicket = new FormsAuthenticationTicket(1, txtuid.Text, DateTime.Now, DateTime.Now.AddDays(1),false,RoleName,FormsAuthentication.FormsCookiePath);
                    string encryptedTocket = FormsAuthentication.Encrypt(AuthTicket);
                    HttpCookie AuthCookie = new HttpCookie(FormsAuthentication.FormsCookieName,encryptedTocket);
                    Response.Cookies.Add(AuthCookie);
                    Response.Redirect(FormsAuthentication.GetRedirectUrl(txtuid.Text, chkRemember.Checked));
                }
                else
                {
                    lblMessage.Text = "Role Deleted";
                }
            }
            else
            {
                 lblMessage.Text = "Wrong username or password";
            }

安全页面:

if (!IsPostBack)
            {
                //Start Authorization Section
                if (!Page.User.Identity.IsAuthenticated)
                {
                    FormsAuthentication.RedirectToLoginPage();
                }
                // End of Authorization Section
            }

1 个答案:

答案 0 :(得分:0)

会话状态超时属性在几分钟内提到

在webconfig文件中......

<system.web>
.......
    <sessionState timeout="1440"></sessionState>
</system.web>

如果网络表格连续24小时闲置,会话将过期。

您只能在。

中拥有此会话状态块