ASP.NET Core禁用响应解压缩 [英] ASP.NET Core Disable response decompression

查看:39
本文介绍了ASP.NET Core禁用响应解压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要禁用响应压缩.我有.NET 4.5版本的web.config,但现在需要.NET CORE 2.x.

I need make response compression disabled. I have .NET 4.5 version of web.config but I need in .NET CORE 2.x now.

<customBinding>
    <binding name="BasicHttpBinding_Service">
        <textMessageEncoding messageVersion="Soap11" />
        <httpsTransport decompressionEnabled="false" />
    </binding>
</customBinding>

我有不支持压缩响应的Web服务,但仍然出现错误: System.ServiceModel.ProtocolException:'响应消息的内容类型application/x-gzip与绑定的内容类型不匹配(text/xml; charset = utf-8).如果使用自定义编码器,请确保正确实施IsContentTypeSupported方法.响应的前653个字节为:?"

I have web service which is not support compressed response and I am still get error: System.ServiceModel.ProtocolException: 'The content type application/x-gzip of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 653 bytes of the response were: '?'

非常感谢您

推荐答案

ASP.NET Core具有

ASP.NET Core has documentation on compression. As you can see, ASP.NET Core no longer uses web.config. If you're hosting your ASP.NET Core app in IIS, then some web.config settings are still used, but only those relevant to generic IIS hosting, nothing application specific (dynamic compression is an IIS feature, so that setting is still relevant, but other web.config settings that used to be relevent in ASP.NET apps are no longer used in ASP.NET Core). Unfortunately I can't find documentation at the moment as to which web.config settings are still relevant.

无论如何,默认情况下,ASP.NET Core使用Kestrel Web服务器,该服务器以代码配置.对我在上面链接的文档中的示例进行一些小的修改,我相信这可能会起作用:

Anyway, ASP.NET Core by default uses the Kestrel web server, which is configured in code. Making a small modification to the sample in the documentation I linked above, I beleive this might work:

public void ConfigureServices(IServiceCollection services)
{
    services.AddResponseCompression(options =>
    {
        var gzip = options.Providers.OfType<GzipCompressionProvider>().FirstOrDefault();
        if (gzip != null)
        {
            options.Providers.Remove(gzip);
        }
    });
}

但这取决于压缩来自何处.如果您在ASP.NET Core应用程序和Internet之间有反向代理(例如IIS,但可能还有nginx,haproxy等),则它们可能正在压缩,因此您需要了解应用程序体系结构并在右侧将其关闭地方.

But it depends where the compression is coming from. If you have a reverse proxy between your ASP.NET Core app and the internet (for example IIS, but maybe nginx, haproxy, etc) they might be doing compression, so you need to understand your application architecture and turn it off at the right place.

这篇关于ASP.NET Core禁用响应解压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆