1

I am looking to add Session Timeout Warning dialog 15 minutes before session expires.The popup indicates session is going to be expired so that user can continue/extend the session or he may logout also

How can i achieve this.

I tried researching on how to do this but I have not find anything that will help me.

I realized i need something like this but I am not sure how a filter will help

Redirect to specific page after session expires (MVC4)

also I looked at http://www.codeproject.com/Articles/227382/Alert-Session-Time-out-in-ASP-Net but i did not make sense to me.

I looked at timeout-dialog.js how can i used this in mvc

help will be apreciated

Community
  • 1
  • 1
DotNetBeginner
  • 412
  • 2
  • 15
  • 34

2 Answers2

3

You should try this

@{
      var conf = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
        var section = (System.Web.Configuration.SessionStateSection)conf.GetSection("system.web/sessionState");
        string timeout = section.Timeout.TotalMinutes.ToString();
 }

<script>
$(document).ready(function () {

                var time = @timeout * 1000 * 60;
                var timeout;
                var isLogout = false;

                timeout = setTimeout(function() {
                    //Things you need to do
                        isLogout = true;

                }, time);

                $(document).on('click', function () {
                    if (!isLogout) {
                        clearTimeout(timeout);
                        timeout = setTimeout(function() {
                            //Things you need to do
                             isLogout = true;
                        }, time);
                    }
                });
            });
</script>
Jigarb1992
  • 828
  • 2
  • 18
  • 41
1

How to know when OWIN cookie will expire?

Looks like what you are talking about? Let me know if it isn't.

Community
  • 1
  • 1
Pandamonium99
  • 174
  • 1
  • 10
  • No I want want timeout-dialog.js does. but i don't know how i can incorporate it in my project. – DotNetBeginner Nov 05 '15 at 20:07
  • Yes, so use the above code, pass the UTC time until expires down with your view model, or to a JS call, every so often. Then when "x" amount of time is left before the token expires, popup a modal or whatever; EX: You can use an ajax call to a controller function that gets the time until the token expires. Once that time is returned to the JS you can use the library. – Pandamonium99 Nov 05 '15 at 20:12
  • i understand that but i am not using OWIN I am using form authentication. How will it work? Will it work? – DotNetBeginner Nov 05 '15 at 20:13
  • form authentication is depreciated and does not use Claims, my best guess for a work around would be: Store the expiration date in the session when the cookie is generated. Then check the session which is attached to the users ID, and grab the expiration time, calculate the time left before it expires then pass that down to javascript. – Pandamonium99 Nov 05 '15 at 20:19