How to determine session timeouts when using cookieless sessions

I am currently working on an ASP.Net 3.5 project and am trying to implement session timeout detection. I know how to do this with included session files, but without total loss.

When a session timeout occurs, I want to redirect the user to some user page.

Can someone explain to me how to do this?

My cookie-based solution looks like this and I will not reproduce its behavior:

if (Session.IsNewSession && (Request.Cookies["ASP.NET_SessionId"] != null))
    Response.Redirect("...");
+3
source share
5 answers

Looks like I found a solution. I am not very happy with this, but at the moment it works.

I added a hidden field to my page layout

<asp:HiddenField ID="sessionID" runat="server" />

CodeBehind

public void Page_Load(object sender, EventArgs eventArgs)
{
    if (Context.Session != null) {
        if (Context.Session.IsNewSession) {
            if (!string.IsNullOrEmpty(sessionID.Value)) {
               Response.Redirect("~/Timeout.aspx")
            }
        }
        sessionID.Value = Context.Session.SessionID;   
    }
}

Web.config ASP

<sessionState cookieless="true" regenerateExpiredSessionId="false"/>

ExpiredSessionId .

+2

Session_End global.asax , .

-edit:

Session.IsNewSession

, .

+2

- , ASP.NET URL-. > n , .

- , , , , ( ).

0

" " AnthonyWJones :

- ASP.Net: Session.IsNewSession SessionCookie?

SessionID - , SessionID URL-, SessionID, - .

, , , .

0

If you don't like it Session_End, you can try a very quick and dirty solution. Set the value Session["Foo"]to Session_Startin global.asax, then check Session["Foo"]on your page. If null, the session has expired.

This is one of the solutions offered by Nikhil Blog . Check it out.

-1
source

Source: https://habr.com/ru/post/1717249/


All Articles