如何在 asp.net MVC 中压缩内容?
如何压缩由 ASP.NET MVC 应用程序发送的输出?
how to compress the output send by an asp.net mvc application??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何压缩由 ASP.NET MVC 应用程序发送的输出?
how to compress the output send by an asp.net mvc application??
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
这是我使用的(截至目前):
控制器中的使用:
还有其他变体,但这效果很好。 (顺便说一句,我在 BaseController 上使用 [压缩] 属性来保存整个项目的重复,而上面是在逐个控制器的基础上进行的。
[编辑] 如上面段落中所述。为了简化使用,您还可以在 BaseController 本身中包含
[Compress]
oneshot,这样每个继承的子控制器默认都会访问该功能:Here's what i use (as of this monent in time):
usage in controller:
there are other varients, but this works quite well. (btw, i use the [Compress] attribute on my BaseController to save duplication across the project, whereas the above is doing it on a controller by controller basis.
[Edit] as mentioned in the para above. to simplify usage, you can also include
[Compress]
oneshot in the BaseController itself, thereby, every inherited child controller accesses the functionality by default:看看 这篇文章 概述了利用操作过滤器的巧妙方法。
例如:
作为一个额外的好处,它还包括一个 CacheFilter。
Have a look at this article which outlines a nifty method utilizing Action Filters.
For example:
And as an added bonus, it also includes a CacheFilter.
对于 .NET Core 2.1,有一个可以使用的新包 ( Microsoft.AspNetCore.ResponseCompression )
安装该包后,可以使用简单的示例:
您可以在此处阅读有关它的更多信息:https://learn.microsoft.com/en-us /aspnet/core/performance/response-compression?view=aspnetcore-2.1&tabs=aspnetcore2x
For .NET Core 2.1 there is a new package that can be used ( Microsoft.AspNetCore.ResponseCompression )
Simple sample to get going, after installing the package:
You can read more about it here: https://learn.microsoft.com/en-us/aspnet/core/performance/response-compression?view=aspnetcore-2.1&tabs=aspnetcore2x