How can I redirect to a page when the user session expires?

前端 未结 11 1710
我在风中等你
我在风中等你 2020-12-28 20:25

I am currently working on an web application that uses ASP.NET 2.0 framework. I need to redirect to a certain page, say SessionExpired.aspx, when the user session expires. T

11条回答
  •  北海茫月
    2020-12-28 20:42

    If I understand correctly, "Session_End" fires internally and does not have an HTTP context associated with it:

    http://forums.asp.net/t/1271309.aspx

    Therefore I don't think you could use it to redirect the user. I've seen others suggest using the "Session_OnStart()" event in the global.ascx file:

    http://forums.asp.net/p/1083259/1606991.aspx

    I have not tried it, but putting the following code in "global.ascx" might work for you:

    void Session_OnStart() {
        if (Session.IsNewSession == false )
        {
        }
        else 
        {
            Server.Transfer("SessionExpired.aspx", False);
        }
    }
    

提交回复
热议问题