asp,.net session如何让会话长时间保持活动

时间:2018-01-21 10:46:48

标签: c# asp.net webforms

我不知道问题出在哪里?我需要保持当前会话保持活动直到客户端注销但我尝试了很多并且所有解决方案都没有意义,并且在每个网页中我应该检查Page_load如果会话仍然有价值或

if (string.IsNullOrEmpty(Session["Postion"] as string))
{
    Response.Redirect("Login.aspx");
}

防止网站崩溃。因此,如果我从所有页面中删除此行,我将获得此

this screenshot problem

它也应该重定向到基于webconfig的Login.aspx页面,但存在同样的问题,这里是Web.Config文件

<configuration>
<configSections>
    <sectionGroup name="devExpress">
        <section name="themes" type="DevExpress.Web.ThemesConfigurationSection, DevExpress.Web.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false"/>
        <section name="compression" type="DevExpress.Web.CompressionConfigurationSection, DevExpress.Web.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false"/>
        <section name="settings" type="DevExpress.Web.SettingsConfigurationSection, DevExpress.Web.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false"/>
        <section name="errors" type="DevExpress.Web.ErrorsConfigurationSection, DevExpress.Web.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false"/>
        <section name="resources" type="DevExpress.Web.ResourcesConfigurationSection, DevExpress.Web.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false"/>
    </sectionGroup>
</configSections>
<system.web>
    <httpRuntime maxRequestLength="2048"/>
    <compilation debug="true" targetFramework="4.0">
        <assemblies>
            <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="DevExpress.Dashboard.v17.1.Web, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
            <add assembly="DevExpress.Dashboard.v17.1.Core, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
            <add assembly="DevExpress.Web.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
            <add assembly="DevExpress.DataAccess.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
            <add assembly="DevExpress.Data.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
            <add assembly="DevExpress.Office.v17.1.Core, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
            <add assembly="DevExpress.PivotGrid.v17.1.Core, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
            <add assembly="DevExpress.Web.Resources.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
            <add assembly="DevExpress.Printing.v17.1.Core, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
            <add assembly="DevExpress.XtraReports.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
            <add assembly="DevExpress.Charts.v17.1.Core, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
            <add assembly="DevExpress.Xpo.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
            <add assembly="DevExpress.RichEdit.v17.1.Core, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
            <add assembly="DevExpress.Pdf.v17.1.Core, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
            <add assembly="DevExpress.Web.Bootstrap.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/></assemblies>
    </compilation>
    <authentication mode="Forms">
        <forms name="MyAuth" timeout="7000000" protection="All" loginUrl="~/Login.aspx" slidingExpiration="true"/>
    </authentication>
    <pages validateRequest="false">
        <controls>
            <add tagPrefix="asp" assembly="DropDownListChosen" namespace="DropDownListChosen"/>
        </controls>
    </pages>
    <httpModules>
        <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule"/>
    </httpModules>
    <httpHandlers>
        <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET" path="DX.ashx" validate="false"/>
    </httpHandlers>
</system.web>
<connectionStrings>
    <remove name="LocalSqlServer"/>
    <add connectionString="Data Source=167.114.12.244;Initial Catalog=Wash;Integrated Security=False;User ID=BeljWash;Password=A100310021001a;Connect Timeout=15;Encrypt=False;Packet Size=4096;user instance=False " name="ConnectionString"/>
</connectionStrings>
<system.webServer>
    <modules>
        <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule"/>
    </modules>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
        <add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v17.1, Version=17.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET" path="DX.ashx" name="ASPxHttpHandlerModule" preCondition="integratedMode"/>
    </handlers>
</system.webServer>
<devExpress>
    <themes enableThemesAssembly="true" styleSheetTheme="" theme="" customThemeAssemblies="" baseColor="" font=""/>
    <compression enableHtmlCompression="false" enableCallbackCompression="true" enableResourceCompression="true" enableResourceMerging="true"/>
    <settings accessibilityCompliant="false" bootstrapMode="Bootstrap3" doctypeMode="Html5" rightToLeft="false" checkReferencesToExternalScripts="true" protectControlState="true" ieCompatibilityVersion="edge"/>
    <errors callbackErrorRedirectUrl=""/>
</devExpress>

1 个答案:

答案 0 :(得分:0)

如果您想为会话设置超时!使用类似这样的东西

QChart *chart = new QChart();
chart->addSeries(series); // addSeries must be called first

QPen pen = series->pen();
pen.setWidth(1);
series->setPen(pen);

其中20分钟! 会话不会在20分钟之前到期,或直到你从Code Behind中取消它们! 谢谢:))