我做了一个自定义的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对象?
我用IIS之前已经看到了这一点。
从内存中,你可以试试这个:
认为这是我如何围绕它在过去得到了