Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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
}

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.

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

There is a setting in IIS as well that may need to be updated, the "idle timeout" setting. The difference is explained here.

By default Idle Timeout is set to 20 minutes, so you will want to set that to 180. This can be done by going into IIS > Application Pools > Right Click Your App Pool > Advanced Settings:

enter image description here

I had the same issue in my ASP.NET MVC web project. Using the following method to set the session duration in the Global.asax.cs file works:

public class ApplicationName : System.Web.HttpApplication
{
    protected void Session_Start(object sender, EventArgs e)
    {
        /* Sets the session duration to 60 minutes. */
        Session.Timeout = 60;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top