我怎样才能重定向到一个页面,当用户会话过期? [英] How can I redirect to a page when the user session expires?

查看:107
本文介绍了我怎样才能重定向到一个页面,当用户会话过期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在对使用ASP.NET 2.0框架的Web应用程序。我需要重定向到某个页面,说SessionExpired.aspx,当用户会话过期。有很多的项目页面,因此增加code到网站的每个网页是不是一个真正的好办法。我有MasterPages不过,我认为这可能会有帮助。

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. There are lot of pages in the project, so adding code to every page of the site is not really a good solution. I have MasterPages though, which I think might help.

谢谢!

推荐答案

您可以在在session_start事件Global.asax中处理这个问题。您可以检查在那里请求会话cookie。如果会话cookie存在,会话已过期:

You can handle this in global.asax in the Session_Start event. You can check for a session cookie in the request there. If the session cookie exists, the session has expired:

   public void Session_OnStart()
    {
        if (HttpContext.Current.Request.Cookies.Contains("ASP.NET_SessionId") != null)
        {
            HttpContext.Current.Response.Redirect("SessionTimeout.aspx")
        }

    }

唉!我还没有发现查不到会话cookie的名称的任何优雅的方式。

Alas I have not found any elegant way of finding out the name of the session cookie.

这篇关于我怎样才能重定向到一个页面,当用户会话过期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆