【发布时间】:2012-11-10 12:40:50
【问题描述】:
我正在开发一个基于 API 的网站,客户端正在.Net MVC 中开发。对于异常处理,我使用的是
public void Application_Error(object sender, EventArgs e)
{
string action = "Index";
Exception exception = Server.GetLastError();
Response.Clear();
HttpException httpException = exception as HttpException;
if (httpException != null)
{
switch (httpException.GetHttpCode())
{
case 404:
// page not found
action = "Error404";
break;
default:
action = "Index";
break;
}
// clear error on server
Server.ClearError();
}
Response.Redirect(String.Format("/error/{0}", action));
}
所以对于控制器的 try catch 抛出的任何异常,页面都会重定向到错误页面。
现在我希望当会话过期时它应该重定向到登录页面,我该怎么做?
现在发生的事情是,在会话到期后,当我尝试访问会话值时,它会抛出异常“object reference not set to an instance of object”。然后它会重定向到默认的错误页面。
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 razor session-state