我的网络服务支持 flex/flash 客户端,并且在出现未处理的异常时,抛出扩展 System.ServiceModel.FaultException 的自定义错误。
我被告知,如果 http 响应代码不是 200,则 flex/flash 无法读取这些自定义错误。这被记录为 flex/flash 错误:http://bugs.adobe.com/jira/browse/SDK-11841
我需要在未处理异常时覆盖 http 返回码。我试图通过将此代码包含在 global.asax 中来做到这一点(此 hack 已被记录为一种解决方法):
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
if (Response.StatusCode != 200)
{ // fix response code for flex
Response.StatusCode = 200;
}
}
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
if (Response.StatusCode != 200)
{ // fix response code for flex
Response.StatusCode = 200;
}
}
但是,唉,当遇到未处理的异常时,我的 http 返回代码返回为 500
有什么想法吗?
最佳答案
在更改响应状态代码之前,您可能需要添加以下代码:
HttpContext.Current.ClearError()
这应该可以防止您的状态代码更改被覆盖。
关于c# - 需要覆盖来自 asmx web 服务的 Http 响应代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/804274/