timeout in asp.net
Forms authentication timeout vs sessionState timeout
They are different things.
The Forms Authentication Timeout value sets the amount of time in minutes that the authentication cookie is set to be valid, meaning, that after value number of minutes, the cookie will expire and the user will no longer be authenticated - they will be redirected to the login page automatically-. The slidingExpiration=true value is basically saying that after every request made, the timer is reset and as long as the user makes a request within the timeout value, they will continue to be authenticated. If you set slidingExpiration=false the authentication cookie will expire after value number of minutes regardless of whether the user makes a request within the timeout value or not.
The SessionState timeout value sets the amount of time a Session State provider is required to hold data in memory (or whatever backing store is being used, SQL Server, OutOfProc, etc) for a particular session.
For example, if you put an object in Session using the value in your example, this data will be removed after 30 minutes.
The user may still be authenticated but the data in the Session may no longer be present.
The Session Timeout value is always reset after every request.
Session timeout vs Forms Authentication timeout
问题
I have been using ASP.NET MVC 2, 3 for a couple years now and we are moving to MVC 4.
We're migrating to SimpleMembership and needed to make changes to the web.config.
However, suddenly I got utterly confused with the timeout values in web.config.
In addition to using SimpleMembership we also want to increase the session timeout from the standard 20 to 30 minutes, so I changed the following configuration setting.
<sessionState timeout="30" mode="InProc" />
I presume this is correct.
But then a co-worker of mine suggested that we also need to change the following timeout value from 20 to 30.
<forms loginUrl="~/Login" timeout="20" />
Is this necessary? If so, could someone explain how the two are related?
答案
Yes, and ideally the both timeout should be kept in sync. The best way to do this is using HttpModule or using filters in MVC. Now, why is this necessary..
Forms authentication timeout indicates, how long a user is recognised and stay authenticated in case of any lack of inactivity
and similarly session timeout indicates how long to preseve users session in case of any inactivity.
Now imagine this case... (simplified for clarification purpose).
You have a ecommerce application where the items are stored in a session, when the users "say" does an "Add to cart operation". Now how long you want this value available in session is determined by your session timeout.
But say your session timeout is 10 minutes and your forms authentication timeout is 30 minutes, so in case of any lack of activity, the user may lose what he has added to the cart after 20 minutes of inactivity wheres the users is still authenticated for another 20 minutes after session timeout....In this case after 10 minutes of inactivity the users session is lost while he still being logged in successfully. To avoid issues like this and there will be many more other cases, its better to keep the session and forms auth. timeout in sync.
Keeping both in sync avoid inconsistency in user experience. (There could be other use cases where session timeout could be less than auth timeout, in that case the application should handle all the edge cases)..
Hope I am able to present the example.. In case of any further clarification do revert back.
ASP.NET Session Timeouts
In ASP.NET there are lots of timeouts. In this blog entry I will be covering in great detail Session timeout due to the complexity of the issue and the fact that I can never remember where all the setting are and what they are for. I am not covering other timeouts except Script Timeout.
SIDE
NOTE: Web services that you consume have timeouts before ASP.NET stops
waiting for a response from a web service, but I am not covering that
here. The web services on the server side have timeouts that are
independent of the ASP.NET consuming the web service. I am also not
covering timeouts associated with database connections or authentication
either. It is however important that all these timeouts be be
compatible with each other, otherwise you will get undesirable behavior.
For example, don't set your execution time to less than the database
timeout. Or don't set the application recycle to be less than the
session timeout.
SessionState Timeout
This
is the number of minutes before an ASP.NET user session is terminated.
It must be an integer, and it is in minutes. The default is to terminate
the session after 20 minutes and the application will throw an
exception when accessing an terminated session. Another way to think of
this is that it is the time between requests for a given session (which
is per user) before a session is terminated.
I recommend reading Idle Timeout section below to see how these are related.
Session Timeout Event
When
the session times out it fires an event called: Session_End
and then
when the user hits the page again (after it has expired or the first
time), it will start a new session and the Session_Start event is
called.
It is important to know that the only thing you can really do in
the Session_End event is do clean up.
This is because this event fire
even if a user doesn't hit a page again.
In other words, if a session
times out due to inactivity, the Session_End is fired even if the user
never refreshes the page, etc.
It is independent of the page lifecycle.
These events are defined in the Global.asax file.
Detecting when a session has timed out
The short answer to this is that you have a session time when the following conditions are met:
Context.Session != null
AND Context.Session.IsNewSession == true
AND Page.Request.Headers["Cookie"] != null
AND Page.Request.Header["Cookie"].indexOf("ASP.NET_SessionId") >= 0
The long answer is read this blog for more details and sample code: http://www.eggheadcafe.com/articles/20051228.asp
and http://aspalliance.com/520
timeout in role manager
https://msdn.microsoft.com/en-us/library/ms164660(v=vs.100).aspx
https://msdn.microsoft.com/en-us/library/system.web.security.roles.cookietimeout(v=vs.110).aspx
<roleManager defaultProvider="SqlProvider"
enabled="true"
cacheRolesInCookie="true"
cookieName=".ASPROLES"
cookieTimeout="30"
cookiePath="/MyApplication"
cookieRequireSSL="true"
cookieSlidingExpiration="true"
cookieProtection="Encrypted" >
<providers>
<add
name="SqlProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="SqlServices"
applicationName="MyApplication" />
</providers>
</roleManager>
https://support.microsoft.com/en-us/help/910439
The forms authentication ticket times out
The other common cause for a user to be redirected is if the forms authentication ticket has expired. The forms authentication ticket can time out in two ways. The first scenario occurs if you use absolute expiration. With absolute expiration, the authentication ticket expires when the expiration time expires. For example, you set an expiration of 20 minutes, and a user visits the site at 2:00 PM. The user will be redirected to the login page if the user visits the site after 2:20 PM.
If you use sliding expiration, the scenario is a
bit more complicated. The cookie and the resulting ticket are updated if
the user visits the site after the expiration time is half-expired. For
example, you set an expiration of 20 minutes by using sliding
expiration. A user visits the site at 2:00 PM, and the user receives a
cookie that is set to expire at 2:20 PM. The expiration is only updated
if the user visits the site after 2:10 PM. If the user visits the site
at 2:09 PM, the ticket is not updated because half of the expiration
time has not passed. If the user then waits 12 minutes, visiting the
site at 2:21 PM, the ticket will be expired. The user is redirected to
the login page.
https://www.codeproject.com/Articles/534693/Authentication-vs-Session-timeout-Session-expired
设置timeout
Forms authentication的timeout设置
<authentication mode="Forms">
<forms timeout="1440" slidingExpiration="true" />
</authentication>
session的timeout的设置
<sessionState timeout="1440" />
timeout in asp.net的更多相关文章
- asp.net mvc Session RedisSessionStateProvider锁的实现
最近项目用到了RedisSessionStateProvider来保存session,发现比内存session慢,后来慢慢了解,发现asp.net session是有锁的.我在文章 你的项目真的需要S ...
- [转]SQL Server Reporting Services - Timeout Settings
本文转自:https://social.technet.microsoft.com/wiki/contents/articles/23508.sql-server-reporting-services ...
- Authentication in asp.net
https://docs.microsoft.com/en-us/aspnet/web-forms/overview/older-versions-security/introduction/an-o ...
- web.config 配置
一.认识Web.config文件 Web.config 文件是一个xml文本文件,它用来储存 asp.NET Web 应用程序的配置信息(如最常用的设置asp.NET Web 应用程序的身份验证方 ...
- 关于多台机器之前session共享,sessionState mode="StateServer" 问题的困扰
.net 多台机器共享session是很老的技术,一直很少用到session. 最近就出现了一个问题:三台前端,其中一台保存的session值死活不对,一样的环境,一样的配置文件,就是和另外两台获得的 ...
- SqlServer Session共享注意点
公司下派任务,之前的网站是一台服务器,由于用户过多,负载过大,现在老大要求多加一台服务器.加就加贝,应该跟我这DEV没有 关系吧,应该不会碰到Source的吧.但是,之前网站有一些数据是放在Sessi ...
- Web.config文件 详解
一.认识Web.config文件Web.config 文件是一个XML文本文件,它用来储存 ASP.NET Web 应用程序的配置信息(如最常用的设置ASP.NET Web 应用程序的身份验证方式), ...
- Web.Config全攻略
一.认识Web.config文件 Web.config 文件是一个xml文本文件,它用来储存 asp.NET Web 应用程序的配置信息(如最常用的设置asp.NET Web 应用程序的身份验证方 ...
- ASP.NET Misconfiguration: Excessive Session Timeout
Abstract: An overly long authentication timeout gives attackers more time to potentially compromise ...
随机推荐
- python利用requests统计1个接口的响应时间
参照 https://www.cnblogs.com/yoyoketang/p/8035428.html requests统计接口的响应时间有2种方式 r.elapsed.total_seconds( ...
- CAD如何设置系统变量
主要用到函数说明: MxDrawXCustomFunction::Mx_SetSysVar 设置系统变量.详细说明如下: 参数 说明 CString sVarName 系统变量名 Value 需要设置 ...
- 生成count个[0-n)不重复的随机数
代码来自:https://www.cnblogs.com/ningvsban/p/3590722.html,感觉实现的方式不错(做了一点小小修改) public static ArrayList ge ...
- ThinkPHP---辅助方法
[三]Tp常见的辅助方法 原生SQL语句里除了目前所使用的基本操作增删改查,还有类似于group.where.order.limit等这样的字句. ThinkPHP封装了相应的子句方法:封装的方法都在 ...
- 如何在MONO 3D寻找最短路路径
前段时间有个客户说他们想在我们的3D的机房中找从A点到B点的最短路径,然而在2D中确实有很多成熟的寻路算法,其中A*是最为常见的,而这个Demo也是用的A*算法,以下计算的是从左上角到右下角的最短路径 ...
- 题解 [USACO18DEC]Balance Beam
被概率冲昏的头脑~~~ 我们先将样例在图上画下来: 会发现,最大收益是: 看出什么了吗? 这不就是凸包吗? 跑一遍凸包就好了呀,这些点中,如果i号点是凸包上的点,那么它的ans就是自己(第二个点),不 ...
- Codeforces Round #470 Div. 2题解
A. Protect Sheep time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 实验1“C语言开发环境使用和数据类型、运算符、表达式”总结与体会
一.实验结论 1.判断奇偶 // 程序功能: // 要求用户从键盘输入一个整数,判断其是奇数还是偶数 #include <stdio.h> int main() { int x; prin ...
- 如何相互转换逗号分隔的字符串和List --https://blog.csdn.net/yywusuoweile/article/details/50315377
如何相互转换逗号分隔的字符串和List ---https://blog.csdn.net/yywusuoweile/article/details/50315377 方法 2: 利用Guava的Joi ...
- MVC系统学习2—MVC路由
在MVC下不是通过对物理文件的映射来实行访问的,而是通过定义后的路由Url来实现访问的.在前一篇讲到我们是在全局文件下进行路由配置. routes.MapRoute( & ...