asp.net – Controller.Execute呈现为没有内容类型的文本文件
发布时间:2020-12-16 06:33:07 所属栏目:asp.Net 来源:网络整理
导读:当404或500发生时,页面显示为文本文件.响应中的内容类型为空.我该如何解决这个问题,以便内容呈现为“text / html”页面. protected void Application_Error() { var context = new HttpContextWrapper(Context); if (!context.Request.IsAjaxRequest()) { va
当404或500发生时,页面显示为文本文件.响应中的内容类型为空.我该如何解决这个问题,以便内容呈现为“text / html”页面.
protected void Application_Error() { var context = new HttpContextWrapper(Context); if (!context.Request.IsAjaxRequest()) { var unhandledException = Server.GetLastError(); var httpException = unhandledException as HttpException; if (httpException == null) { var innerException = unhandledException.InnerException; httpException = innerException as HttpException; } var routeData = new RouteData(); routeData.Values.Add("controller",MVC.Errors.Name); if (httpException != null) { var httpCode = httpException.GetHttpCode(); switch (httpCode) { case (int)HttpStatusCode.NotFound: routeData.Values.Add("action","PageNotFound"); Server.ClearError(); IController pageNotFoundController = new ErrorsController(); pageNotFoundController.Execute(new RequestContext(new HttpContextWrapper(Context),routeData)); break; } } else { routeData.Values.Add("action","Error"); Server.ClearError(); IController errorController = new ErrorsController(); errorController.Execute(new RequestContext(new HttpContextWrapper(Context),routeData)); } } } 解决方法
我添加了这个并修复了它.
if (!context.Request.IsAjaxRequest()) { context.Response.ContentType = "text/html"; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- wcf – SOAP API HTTPS – 与经典ASP连接
- WeihanLi.Npoi 1.11.0/1.12.0 Release Notes
- asp.net – 无法加载viewstate.正在加载viewstate的控制树
- asp.net-mvc – 将mvc3中的下拉列表绑定到字典?
- 如何默认选择一个单选按钮 – asp.net mvc强类型的html助手
- ASP.NET:WebResource.axd调用404错误:如何知道哪个程序集
- asp.net-web-api – 根据Web API请求设置JSON CamelCase
- asp.net – 在服务器而不是数据库中拥有(可能)数千个目录的
- asp.net – 获取在page_init中触发回发的控件
- Orchard Core一分钟搭建ASP.NET Core CMS
推荐文章
站长推荐
热点阅读