C# 正在asp.net web应用程序中放弃会话

C# 正在asp.net web应用程序中放弃会话,c#,asp.net,web-config,C#,Asp.net,Web Config,我有一个asp.net c#web应用程序在服务器上运行,我的应用程序在1分钟后仍将我发送到登录页,我的服务器提供商说服务器配置没有问题,我已将我的web.config文件定义如下: <?xml version="1.0"?> <configuration> <connectionStrings> <add name="myConnectionString" connectionString="Data Source=123.123.123.123;Us

我有一个asp.net c#web应用程序在服务器上运行,我的应用程序在1分钟后仍将我发送到登录页,我的服务器提供商说服务器配置没有问题,我已将我的web.config文件定义如下:

<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="myConnectionString" connectionString="Data Source=123.123.123.123;User ID=myUserID;Password=myPassword;"/>
</connectionStrings>
<system.web>
<sessionState timeout="30"></sessionState>
<compilation debug="true" targetFramework="4.5" defaultLanguage="c#">
    <assemblies>
      <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
      <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    </assemblies>
  </compilation>
  <httpRuntime targetFramework="4.5" />
  <httpHandlers>
    <add verb="GET" path="CaptchaImage.axd" type="MSCaptcha.CaptchaImageHandler, MSCaptcha"/>
  </httpHandlers>
<machineKey
validationKey="374A70A6EF0A2F8C1F821D125FCF6503DEA7E9CE467B433086B058D86FAB67338
C3A37E580F29FF27E86D079CC9153E396ABF495821E84C7B7B1F42F4467F1CA"
 decryptionKey="C74E21EE5B3C592C62C1BC5E682ED3CC4BD389CCC3AEA317AE1772E0D6750141"
validation="SHA1" decryption="AES"
/>
</system.web>
<system.webServer>
 <handlers>
  <add name="CaptchaImage" verb="GET" path="CaptchaImage.axd" type="MSCaptcha.CaptchaImageHandler, MSCaptcha"/>
 </handlers>
  <validation validateIntegratedModeConfiguration="false"/>
  <httpErrors errorMode="Custom">
    <remove statusCode="404"/>
   <error statusCode="404" path="~/pr/http404.aspx" responseMode="ExecuteURL"/>
 </httpErrors>
</system.webServer>  
</configuration>

在我的.aspx文件中,我使用下面的代码检查会话

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        if (Session["user"] == null || userRole() != "Admin")
            Response.Redirect("../Default.aspx", false);
        else
        {
            // some code here..
        }
    }
    catch(Exception ex)
    {
        litAlert.Text = "<div class='alert alert-danger' role='alert'><div><span><strong>An error has occured. Please try again</strong></span ></div></div>";
    }
}
受保护的无效页面加载(对象发送方,事件参数e)
{
尝试
{
如果(会话[“用户”]==null | |用户角色()!=“管理员”)
Response.Redirect(“../Default.aspx”,false);
其他的
{
//这里有一些代码。。
}
}
捕获(例外情况除外)
{
litAlert.Text=“发生错误。请重试”;
}
}

非常感谢您的帮助

您是否在IIS中检查了会话超时设置?你有IIS管理员吗?我的控制面板中没有IIS,我有网站的ASP.NET配置,在会话设置部分,我已将会话超时(分钟)设置为30分钟会话[“用户”]是否有值?你查过了吗?是的。为了查看页面,我必须通过login.aspx登录,但在很短的时间内,会话被放弃,我再次被重定向到login.aspx页面。