服务器返回消息是json异常,无法在远程请求上接收JSON异常消息/内容类型

我有一个ASP.NET MVC3应用程序,它使用JSON与Flash UI进行通信。

我使用ActionFilterAttribute来处理JSON异常(来自ASP.NET MVC 2中的Handle JSON Exceptions:http://www.dotnetcurry.com/ShowArticle.aspx?ID = 496):

public class HandleJsonExceptionAttribute : ActionFilterAttribute

{

public override void OnActionExecuted(ActionExecutedContext filterContext)

{

if (filterContext.Exception != null)

{

filterContext.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;

filterContext.Result = new JsonResult()

{

JsonRequestBehavior = JsonRequestBehavior.AllowGet,

Data = new

{

filterContext.Exception.Message,

}

};

filterContext.ExceptionHandled = true;

}

}

}

它在localhost上执行时工作正常,来自fiddler的详细信息:

HTTP/1.1 500 Internal Server Error

Cache-Control: private

Content-Type: application/json; charset=utf-8

Server: Microsoft-IIS/7.5

X-AspNetMvc-Version: 3.0

X-AspNet-Version: 4.0.30319

X-Powered-By: ASP.NET

Date: Mon, 11 Apr 2011 19:05:21 GMT

Content-Length: 34

{"Message":"No está autenticado"}

但是,当从远程客户端执行时,例如在LAN上,我得到“Content-Type:text / html”中的响应,而不是“Content-Type:application / json;”并且内容是标准的html错误页面:

500内部服务器错误。

您正在查找的资源存在问题,无法显示。

HTTP/1.1 500 Internal Server Error

Cache-Control: private

Content-Type: text/html

Server: Microsoft-IIS/7.5

X-AspNetMvc-Version: 3.0

X-AspNet-Version: 4.0.30319

X-Powered-By: ASP.NET

Date: Mon, 11 Apr 2011 19:07:53 GMT

Content-Length: 1208

我需要配置什么才能获得远程请求的JSON响应?

我需要flash UI收到一个http 500错误,但用json消息而不是html。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值