asp.net-mvc – IIS显示服务器错误而不是自定义错误
发布时间:2020-09-01 19:02:38 所属栏目:asp.Net 来源:互联网
导读:我正在使用MVC 5,我正在使用自定义视图处理我的错误,例如(404,403 ……等) 它在我的本地IIS上工作正常,但是当我在登台服务器上发布时,它显示有关这些错误代码的IIS服务器错误消息. 它显示了这条消息: 代替: 我修改了web.config for customErrors mode =“Of
我正在使用MVC 5,我正在使用自定义视图处理我的错误,例如(404,403 ……等)
它显示了这条消息: 代替: 我修改了web.config for< customErrors mode =“Off”/> Global.asax中 if ((Context.Server.GetLastError() is UnauthorizedAccessException)) { log.LogError(Context.Server.GetLastError().Message,Context.Server.GetLastError()); customErrorPage = @"~/Error/?id=403"; //security } else if ((Context.Server.GetLastError() is HttpException) && (((HttpException)Context.Server.GetLastError()).GetHttpCode() == 404)) { //** Handle 404 error and response code log.LogError("404",Context.Server.GetLastError()); customErrorPage = @"~/Error/?id=404"; } else { log.LogError(Context.Server.GetLastError().Message,Context.Server.GetLastError()); customErrorPage = @"~/Error"; } if (ConfigurationHelper.Common.ShowCustomErrorPage) { var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); Response.Redirect(urlHelper.Content(customErrorPage),false); Server.ClearError(); } 错误控制器: public ActionResult Index(string id) { if (!string.IsNullOrEmpty(id) && id.Equals("404")) { Response.StatusCode = 404; return !Request.IsAjaxRequest() ? (ActionResult)View("404") : PartialView("404"); } if (!string.IsNullOrEmpty(id) && id.ToLower().Equals("403")) { Response.StatusCode = 403; return !Request.IsAjaxRequest() ? (ActionResult)View("Security") : PartialView("Security"); } return !Request.IsAjaxRequest() ? (ActionResult)View("Index") : PartialView("Index"); } 我应该怎么做以显示我的自定义错误消息? 解决方法只需添加以下web.config配置即可通过IIS默认错误处理行为<configuration> <system.webServer> <httpErrors existingResponse="PassThrough" /> </system.webServer> </configuration> (编辑:甘南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 从单独的配置文件中读取设置
- asp.net-mvc – 使用IIS基本身份验证的OWIN身份验证
- asp.net-mvc – Visual Studio 2010 Full和ASP.NET MVC 2.0
- 如果我的Asp.Net会话有IsNewSession == true,那我的意思是什
- asp.net – Html.Partial()跳过控制器动作
- 为ASP.NET应用程序实现后台服务的最佳方法是什么?
- asp.net-mvc-4 – 最小和最大字符串长度的单独错误消息 –
- 如何通过邮递员使用JSON对象发布到MVC端点
- Asp.net超链接控件相当于
- asp.net全局资源错误’找不到具有键”的资源对象’
推荐文章
站长推荐
- asp.net ajax实现无刷新验证码
- asp.net – 如何正确地大写希腊字在.NET?
- asp.net-mvc-4 – .net 4.5 ASP.Net web API JSO
- iis-7.5 – 使用虚拟目录/应用程序在IIS中托管AS
- asp-classic – 经典的asp / asp.net网站 – glo
- asp.net Web.config 详细配置说明
- asp.net-mvc – 使用asp.net mvc 2功能与火花浏览
- asp.net中XML如何做增删改查操作
- asp.net core标签助手的高级用法TagHelper+Form
- 是否可以直接路由到MVC应用程序中托管的blazor页
热点阅读