Payam Sh
Payam Sh

Reputation: 601

ASP.NET Forms authentication timeout expires too soon

I have read a lot of examples but I dont know why my code doesn't work. This is a part of my web.config code in my ASP.NET project:

  <system.web>
      <authentication mode="Forms">
        <forms loginUrl="Panel/Login" timeout="525600" slidingExpiration="true" />
      </authentication>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" maxRequestLength="1048576" />
  </system.web>

The problem is that when I login, after a few minutes of inactivity when I try to request something I'm navigated to the Login page. This happens even if I set persistent cookie in my Login page!

I've tried to increase and decrease timeout attribute.

I've tried slidingExpiration attribute.

I've tried cookieless attribute.

None of them works!

I use this code in Login page:

FormsAuthentication.SetAuthCookie(Username.Text, Remember_Me.Checked);

Thanx in advance.

Upvotes: 0

Views: 2446

Answers (1)

Nikolay
Nikolay

Reputation: 329

You can try to add machineKey to your code :

<machineKey validationKey=”AutoGenerate”

You can see more detailed information here :

http://blog.falafel.com/asp-net-forms-authentication-times-out-on-a-shared-host/

Or this maybe in help :

Asp.net forms authentication cookie not honoring timeout with IIS7

Upvotes: 3

Related Questions