重定向到global.asax(session_end事件)中的登录页面时出错 [英] Error in redirecting to login page inside global.asax (session_end event)

查看:255
本文介绍了重定向到global.asax(session_end事件)中的登录页面时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void Session_End(object sender, EventArgs e)
       {
            Response.Redirect("Default.aspx");
       }







我在会话到期时使用上面的代码重定向到默认页面。

但它抛出异常。






I am using above code to redirect to default page when Session expires.
But it throws exception.

An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code

Additional information: Response is not available in this context.







请帮忙。



先谢谢。



< b>我尝试了什么:






Please help .

Thanks in Advance.

What I have tried:

protected void Session_End(object sender, EventArgs e)
        {
             Response.Redirect("Default.aspx");
        }

推荐答案

会话结束事件不会从页面请求中触发,因此您无法访问请求或响应对象。考虑一下....我的会话过期因为我在20分钟前关闭了我的浏览器,你期望response.redirect做什么?
The Session End event doesn't fire from a page request so you can't access the Request or Response objects. Think about it....my session exires because I closed my browser down 20 minutes ago, what do you expect response.redirect to do?


这篇关于重定向到global.asax(session_end事件)中的登录页面时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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