IIS默认返回HTML错误,而不是JSON,按指示

问题描述 投票:0回答:1

我做了一个自定义的Attribute在我的ASP.NET MVC项目,指示服务器返回一个JSON对象特定的目的,而不是处理错误的常用方法。该属性看起来是这样的:

public class AjaxErrorHandler : FilterAttribute, IExceptionFilter
{
    public void OnException(ExceptionContext filterContext)
    {
        if (filterContext.HttpContext.Request.IsAjaxRequest())
        {
            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
            filterContext.HttpContext.Response.StatusDescription =
                filterContext.Exception.Message.Replace('\r', ' ').Replace('\n', ' ');
            filterContext.Result = new JsonResult
            {
                Data = new { errorMessage = filterContext.Exception.Message }
            };
        }
    }
}

每当我在本地调试解决方案,它工作得很好,并返回出错如下:

{"errorMessage":"Error message goes here"}

但是,当我部署的解决方案,我的生产服务器,该服务器consistantly返回以下HTML:

 #content{margin:0 0 0 2%;position:relative;}
 .content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
 -->
 </style>
 </head>
 <body>
 <div id = "header" >< h1 > Server Error</h1></div>
 <div id = "content" >
     < 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>
 </div>
 </body>
 </html>

我错过了什么配置的Web项目的位置,以使服务器荣誉指令返回的JSON对象?

asp.net-mvc iis asp.net-mvc-5
1个回答
1
投票

我用IIS之前已经看到了这一点。

从内存中,你可以试试这个:

  • 打开IIS管理器
  • 选择有问题的网站
  • 双击错误页面图标
  • 在右侧点击编辑功能设置
  • 将设置更改为详细的错误信息进行本地和自定义错误页的远程请求
  • 再次尝试该网站

认为这是我如何围绕它在过去得到了

© www.soinside.com 2019 - 2024. All rights reserved.