0

I have spent days trying to find the answer to this question so I apologise in advance if there is an immediate answer somewhere! I've looked and couldn't find anything that worked for me.

I want my site to automatically log the user out once the Forms Authentication timeout has expired. What it does at the moment is expire the authentication, but the user is left signed in until they make a request / click on a link. This will then trigger the redirect and they are taken back to the login page.

I have tried using javascript on an interval to look at the timeout left and then check if it's expired then call the logoff() action, however these javascript calls are themselves "requests" therefore the site will never log out.

Here is the web.config settings for form authentication:

<authentication mode="Forms">
      <forms loginUrl="~/Account/RedirectLogin" name=".ASPXAUTH" timeout="30"/>
    </authentication>

Thanks!

iandavidson1982
  • 190
  • 3
  • 17
  • I think you might be looking to use Session Timeout http://stackoverflow.com/questions/484964/asp-net-push-redirect-on-session-timeout and a more recent http://www.c-sharpcorner.com/UploadFile/0c1bb2/redirect-page-after-session-time-out-in-Asp-Net424/ – Aymeric Mar 14 '16 at 12:11

1 Answers1

0

In your master page you can define a special header tag that will redirect user after session have expired:

protected override void OnPreRender(EventArgs e)
{
    base.OnPreRender(e);
    this.PageHead.Controls.Add(new LiteralControl(
       String.Format("<meta http-equiv='refresh' content='{0};url=/Login.aspx'>", 
       Session.Timeout * 60 + 1)));
}
Lesmian
  • 3,932
  • 1
  • 17
  • 28