0

I use a session cookie to store an int when users first visit the system which is based on windows authentication. The cookie is set using this method

public ActionResult SetContractId(int contractId)
{
    Session["LoggedContractId"] = contractId;

    return RedirectToAction("IndexLoggedIn");
}

And access it in other methods using this

var creatorContractId = (int)Session["LoggedContractId"];

However this cookie times out after 20 mins and I cant seem to control this time

I have tried this in the webconfig

<system.web>
    <sessionState mode="InProc" timeout="1200" />
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
    <authentication mode="Windows" />
    <customErrors mode="Off" />
    <authorization>
        <deny users="?" />
    </authorization>
</system.web>

But it doesnt affect it

1
  • add mode="InProc" attribute to your sessionState element Commented Mar 9, 2016 at 11:27

2 Answers 2

1

It will not work until you don't exceed the application pool recycle time in IIS. This web.config setting takes effect if and only if it is less than or equal to Application Pool recycle settings. By default application pool has a setting of 20 minutes so please change that and then alter the web.config... it will 100% work.

Sign up to request clarification or add additional context in comments.

2 Comments

I'm not familiar with IIS, where abouts is it in IIS8.5?
Go to an application pool in which your website is configured , on the click of application pool on the right side, you can find Advance Settings, click on it, then find Idle Time Out property and change it
0

Add mode also, this will work.

 <system.web>
       <compilation debug="false" targetFramework="4.5.1" />
        <sessionState mode="InProc" timeout="240" />
      </system.web>

4 Comments

sadly that doesn't work still get an error saying that the session cookie isn't set
have you also defined forms timeout in your config?
try after <compilation debug="false" />, can you please add the code where you are accessing Session["LoggedContractId"] ?
In case this is related to idle timeout refer stackoverflow.com/questions/12314472/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.