我想问你这个问题,因为我有点困惑。
我想知道为什么当我连接时感谢我的登录表单,当我在我的默认页面上,在连接1小时后,它会断开连接并返回到登录页面。
这是我的实际webconfig。
<configuration>
<configSections>
</configSections>
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString='Data Source=.\SQLEXPRESS; AttachDbFilename = "C:\Users\Maxime\Documents\Visual Studio 2010\Projects\ClientPortal\ApplicationUI\Website\ClientPortal\App_Data\DataUi.mdf";Integrated Security=True;User Instance=True'
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<pages validateRequest="false" />
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="Logon.aspx" name=".ASPXFORMSAUTH">
</forms>
</authentication>
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
<sessionState cookieless="false"/>
<httpRuntime maxRequestLength="1048576"/>
</system.web>
<appSettings>
<add key="FolderPath" value="uploads" />
</appSettings>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
</configuration>
我应该在网络配置中添加其他内容来禁用此功能吗?
这有点烦人..
答案 0 :(得分:4)
您正在使用ASP.Net表单身份验证。默认超时为30分钟(半小时)我很惊讶它让你闲置一小时。
使用以下代码来控制超时时间。
<system.web>
<authentication mode="Forms">
<forms timeout="50000000"/>
</authentication>
答案 1 :(得分:2)
那是因为你的Session
超时了。
您可以在此问题及其解决方法上阅读here
答案 2 :(得分:1)
在表单标记中,您需要添加slidingExpiration=true
,这样如果用户在一小时内处于活动状态,则用户将无法注销。他们退出的原因是因为会话超时,并且通过使用滑动到期,会话将在每次用户发出请求时延长会话时间。
答案 3 :(得分:1)
这是我用来避免会话过期的小javascript
<script type="text/javascript">
PingAspToKeepSession();
function PingAspToKeepSession() {
var url = "KeppSession.aspx";
var httpOb = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
httpOb.open("POST", url, true);
httpOb.send("");
window.setTimeout("PingAspToKeepSession();", 60000); // every 60 seconds
}
</script>