问题
I have Admin Page wherein I use to do some update work for my site. The problem is the session will expire within a minute or 30 seconds and will logout the user. I have set the Session in Web.Config of the root folder as well as in the Web.Config inside the Admin folder but still the session gets expired soon. I have set it to 60 minutes but it only lasts for 30 seconds or within a minute. Here is my web.config content of root folder
<sessionState timeout="60" mode="InProc"
cookieless="false"></sessionState>
<customErrors mode="Off">
</customErrors>
<trace enabled="true" />
<authentication mode="Forms">
<forms
protection="All"
timeout="120"
domain="www.marpallichande.in"
slidingExpiration="true"
name="auth_cookie" />
</authentication>
and this is my setting of web.cofing file inside the Admin folder
<sessionState timeout="60" mode="InProc"
cookieless="false"></sessionState>
and this is my setting in Global.asax file under Session_Start method
Session.Timeout=60;
I am not getting how the session is getting expired so soon or is there any other reason for been getting logged out other than session.
回答1:
sessionState timeout value is in minutes. I would start by removing Session.TimeOut (and any other timeout values except sessionState timeout, leave it as it is and give it a try. Also, not sure why you have two config files? Do they have same settings?
I have a similar setup but just one config file with
<sessionState mode="InProc" cookieless="false" timeout="10" />
setting it to 10 minutes.
回答2:
write <sessionState mode="InProc" cookieless="false" timeout="10" />
in the global web.config file of your application.
define Session_OnEnd event by adding a subroutine named Session_OnEnd to the Global.asax file. The Session_OnEnd subroutine is run when the method has been called or when the session has expired. A session expires when the number of minutes specified by the Timeout property passes without a request being made for the session.
The Session_OnEnd event is supported only when the session state Mode property is set to InProc.
Session_onEnd event can be defined in global.asax as:
public void Session_OnEnd()
{
// do your desired task when the session expires
}
回答3:
Check the root web.config for a session state setting such as:
//Timeout is in minutes
//Note for using the global.asx about InProc: SessionStateModule.End Event
The Session_OnEnd event is only supported when the session-state HttpSessionState.Mode property value is InProc, which is the default. If the session-state Mode is set to StateServer or SQLServer, then the Session_OnEnd event in the Global.asax file is ignored. If the session state Mode property value is Custom, then support for the Session_OnEnd event is determined by the custom session-state store provider.
<system.web>
<sessionState mode="InProc" cookieless="false" timeout="30" />
</system.web>
You should only have this defined in 1 location.
回答4:
if page logout after some seconds automatically that is because of session expire
<sessionSate mode="StateServer" cookieless="false" timeout="940"/>
write the code in web.config
I find the solution from enter link description here
来源:https://stackoverflow.com/questions/21098047/asp-net-session-state-not-working-in-web-config-as-well-as-global-asax