c# - 需要覆盖来自 asmx web 服务的 Http 响应代码

标签 c# apache-flex http exception soap

我的网络服务支持 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/

相关文章:

html - Angular 2 应用程序 - 链接到本地​​文件

c# - 如何在 EF Code First 中创建/更新 LastModified 字段

c# - 异步任务的 NUnit 测试在 C# 中失败

c# - C# 中的字符串基准 - 重构速度/可维护性

c# - c#下创建事务调用存储过程

apache-flex - 弹性 : does painless programmatic data binding exist?

xml - Flex中可变的声音

http - Golang http客户端为什么有MaxConnsPerHost没有MaxConns

apache-flex - 任何 Flex 4 迁移经验?

php - 带标题下载的文件不起作用