ASP.NET MVC3中的HTML反而不是JSON的IIS响应
发布时间:2020-12-30 18:01:36 所属栏目:asp.Net 来源:互联网
导读:主题是自我介绍的.我有开发人员和生产环境.开发人员环境是我的本地机器.我有一些行为方法,在某些事情出错(或发生错误或逻辑不一致))时,将响应状态代码设置为500,并返回Json-answer.我的常见方法如下: [HttpPost]public ActionResult DoSomething(int id){ tr
主题是自我介绍的.我有开发人员和生产环境.开发人员环境是我的本地机器.我有一些行为方法,在某些事情出错(或发生错误或逻辑不一致))时,将响应状态代码设置为500,并返回Json-answer.我的常见方法如下: [HttpPost] public ActionResult DoSomething(int id) { try { // some useful code } catch(Exception ex) { Response.StatusCode = 500; Json(new { message = "error" },JsonBehaviour.AllowGet) } } 在客户端生产环境当发生这样的错误时,ajax.response看起来像HTML代码,而不是预期的JSON. 考虑这个: <div class="content-container"> <fieldset> <h2>500 - Internal server error.</h2> <h3>There is a problem with the resource you are looking for,and it cannot be displayed.</h3> </fieldset> </div> 过滤器上下文不是一个选项.我认为这是某种IIS或web.config问题. 解: 解决方法我想IIS正在服务一些友好的错误页面.您可以尝试通过在响应上设置TrySkipIisCustomErrors属性来跳过此页面:catch(Exception ex) { Response.StatusCode = 500; Response.TrySkipIisCustomErrors = true; return Json(new { message = "error" },JsonBehaviour.AllowGet) } (编辑:鲜蔬坊站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 认证 – WebApi ActionFilterAttribute,HttpActionContext访
- asp.net实现文件下载的代码
- asp.net – 在fileupload中选择立即调用C#函数文件
- asp.net-mvc – 删除布局将默认为_ViewStart,为什么找不到部
- asp.net-mvc – 用于测试目的的假开放ID提供程序
- asp.net-mvc – 如何在asp.net mvc中处理分页?
- 使用SharpZipLib压缩打包多个内存中的文件
- ASP.Net 分页控件源码
- asp.net – ASP:ItemTemplate中的DropDownList:为什么允许
- ASP.NET设计网络硬盘之删除文件夹实现代码
推荐文章
站长推荐
- asp.net-mvc – ASP.NET MVC中的WebApi [FromUri
- asp.net – 如何接收JSON作为MVC 5操作方法参数
- asp.net – Lucene.Net和孵化状态
- asp.net – Request.Browser.Platform不返回iPad
- 实现ASP.NET多文件上传程序代码
- asp.net-mvc – 从Asp.Net Mvc应用程序找不到Dat
- asp.net-mvc – 命名约定 – 控制器的一个规则,没
- asp.net-mvc – 使用CORS在WebAPI中将text / pla
- 如何在不使用MembershipProvider的情况下使用ASP
- asp.net-mvc – 在OS X 10.7.4上的MonoDevelop中
热点阅读