0

我们很难让会话超时在 ASP.NET 4 中工作。我们将超时设置为 720 分钟(12 小时)。我们正在使用表单身份验证。无论我将超时设置为什么,超时都会在大约 20 分钟后发生。我确定我们配置了错误,但我不确定是什么。我在网上查看了几个修复程序(标题等),但似乎没有任何工作。这是我们的配置文件:

<authentication mode="Forms">
     <forms loginUrl="~/Login.aspx" name="CAFormsAuth" timeout="720" slidingExpiration="true" defaultUrl="Default.aspx" /> </authentication> <authorization>    <!--<allow users="*"/>-->   <deny users="?" /> </authorization>

这是我们的登录代码:

try
        {
            string adLogin = txtUserName.Text;

            bool isValid = false;
            //Validate User against AD First...
            //----------------------------------
            try
            {
                isValid = AuthenticateUser(cboDomains.Text, adLogin, txtPassword.Text);
            }
            catch (Exception ex)
            {
                //Should read "Invalid Username or Password"...
                //lblError.Text = ex.Message;
                lblError.Text = "Invalid User Name or Password.";
                return;                   
            }

            //Now, See if the user exists in the database.
            //---------------------------------------------
            db_users user = null;
            try
            {
                user = usrHelp.GetUserByADUserName(cboDomains.Text + @"\" + adLogin);

                if (user == null)
                {
                    lblError.Text = "User " + adLogin + " does not exist in the database.";
                    return;
                }
            }
            catch (Exception ex)
            {
                ErrorLoggingHelper.LogToSource(Globals.ApplicationName, ex.ToString(), System.Diagnostics.EventLogEntryType.Error);

                lblError.Text = "User " + adLogin + " does not exist in the database.";
                return;
            }

            if (isValid)
            {
                if (chkRemember.Checked)
                {
                    SetCookies();
                }
                else
                {
                    RemoveCookie();
                }
            }
            else
            {
                lblError.Text = "Password is not valid";
                Telerik.Web.UI.RadAjaxManager.GetCurrent(this.Page).ResponseScripts.Add(String.Format("SetFocus('{0}')", txtPassword.ClientID));
                return;
            }

            Session[Globals.LoggedInUserName] = txtUserName.Text;
            Session[Globals.LoggedInUserId] = user.user_id;
            Session["CurrentUser"] = user;

            FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, false);

        }
        catch (Exception ex)
        {
           //deleted error logging code here...
            lblError.Text = "Error authenticating user. Please contact the administrator.";
        }
4

2 回答 2

2

您的 IIS 在应用程序池级别中有一个高级设置。在“进程模式”下有一个“空闲超时”设置,默认设置为 20 分钟。你应该可以在那里改变它。

于 2012-07-30T21:46:45.990 回答
0

尝试在 web.config 中设置会话超时,如下所示:

<configuration>
  <system.web>
    <sessionState mode="InProc" timeout="720" />
  </system.web>
</configuration>
于 2012-07-30T21:44:09.670 回答