我从我的global.ascx文件调用actionResult就像这样...
Response.Redirect(String.Format("~/Error/{0}/?message={1}", action, exception.Message));
Run Code Online (Sandbox Code Playgroud)
我想要做的是在动作结果方法中提供整个异常对象,这样我就可以在我的页面上获取并显示堆栈跟踪信息....是否可以传递整个异常对象?处理这个问题的最佳方法是什么?或者是否有工作来获得正确的堆栈跟踪信息?目前,它是在异常对象上正确填充的属性.
如果重定向,则无法发送复杂对象.我的意思是你可以使用Session和TempData(在幕后使用Session),但它很丑陋,我建议反对.
如果您想要复杂的对象不重定向.设置正确的状态代码和转移,这更加RESTful和SEO友好:
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
Response.Clear();
Context.ClearError();
var routeData = new RouteData();
routeData.Values["controller"] = "error";
routeData.Values["action"] = "Http500";
routeData.Values["exception"] = exception;
IController errorController = new ErrorController();
errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
}
Run Code Online (Sandbox Code Playgroud)
其中ErrorController如下所示:
public class ErrorController : Controller
{
public ActionResult Http500(Exception exception)
{
Response.StatusCode = 500;
// TODO: do something with the exception like logging it
// and render some view explaining the annoyed user
// that something very wrong happened to your application
// which wasn't your fault of course or something
}
}
Run Code Online (Sandbox Code Playgroud)
如果重定向,则无法发送复杂对象.
| 归档时间: |
|
| 查看次数: |
316 次 |
| 最近记录: |