当用户上传超过限制的文件时,我尝试显示错误页面(请参阅
Catching “Maximum request length exceeded”)
在global.asax中,我想重定向到控制器操作,所以这样的东西,但它不工作?
private void Application_Error(object sender,EventArgs e) { if (GlobalHelper.IsMaxRequestExceededEexception(this.Server.GetLastError())) { this.Server.ClearError(); return RedirectToAction("Home","Errorpage"); } }
解决方法
尝试这样:
protected void Application_Error() { var exception = Server.GetLastError(); // TODO: Log the exception or something Response.Clear(); Server.ClearError(); var routeData = new RouteData(); routeData.Values["controller"] = "Home"; routeData.Values["action"] = "ErrorPage"; Response.StatusCode = 500; IController controller = new HomeController(); var rc = new RequestContext(new HttpContextWrapper(Context),routeData); controller.Execute(rc); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。