Get ASP.NET Session Last Access Time (or Time-to-Timeout)

后端 未结 4 552
天涯浪人
天涯浪人 2020-12-18 17:44

I\'m trying to determine how much time is left in a given ASP.NET session until it times out.

If there is no readily available time-to-timeout value, I could also ca

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-18 18:32

    If you are at the server, processing the request, then the timeout has just been reset so the full 20 minutes (or whatever you configured) remain.

    If you want a client-side warning, you will need to create some javascript code that will fire about 20 minutes from "now". See the setTimeout method.

    I have used that to display a warning, 15 minutes after the page was requested. It pops up an alert like "your session will expire on {HH:mm}, please save your work". The exact time was used instead of "in 5 minutes" as you never know when the user will see that message (did he return to his computer 10 minutes after the alert fired?).

提交回复
热议问题