【问题标题】:How to return pre-gziped data from an action in mvc core?如何从 mvc 核心中的操作返回预压缩数据?
【发布时间】:2019-05-04 04:55:34
【问题描述】:

如果我的数据库中有预压缩的数据,当我启用动态压缩时,如何从控制器返回这些数据?有没有办法告诉 iis/mvc 核心“不要重新压缩这个”?

如果我只是返回一个文件数据,我假设 IIS 会重新压缩它并添加内容编码,是否有一种安全的方法让 iis 处理压缩所有内容(静态和动态)并仍然告诉它“不,只是为了这个动作,考虑要预压缩的输出”?

public IActionResult GetImage(int Id)
    {
        var img = Context.Images
            .Single(i => i.Id == Id);
        return new FileContentResult(img.Data, img.MIME); // What could i do if i wanted, just for this action, to have img.Data already compressed in the database, while everywhere else i have it uncompressed and DO want IIS to compress it?
    }

【问题讨论】:

    标签: asp.net-core


    【解决方案1】:

    您可以排除特定的 MIME 类型。

    services.AddResponseCompression(options =>
    {
        options.ExcludedMimeTypes = new List<string> { "image/jpeg" };
    });
    

    对于压缩或不压缩特定操作的更精细控制...我不确定。

    【讨论】:

    • 遗憾的是,我确实需要动作级别的东西,而不是 MIME 类型级别:(
    猜你喜欢
    • 2020-12-18
    • 2018-07-28
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多