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

前端 未结 11 1713
我在风中等你
我在风中等你 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:59

    Are you looking to redirect on the next request, or redirect immediately, without user intervention? If you're looking to redirect without user intervention, then you can use ClientScript.RegisterStartupScript on your Master Page to inject a bit of javascript that will redirect your clients when their session expires.

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        String timeoutPage = "SessionExpired.aspx"; // your page here
        int timeoutPeriod = Session.Timeout * 60 * 1000;
    
        sb.AppendFormat("setTimeout(\"location.href = {0};\",{1});", timeoutPage, timeoutPeriod);
        Page.ClientScript.RegisterStartupScript(this.GetType(), "timeourRedirect", sb.ToString(), true);
    

提交回复
热议问题