Global.asax 上的 ASP.NET gzip 脚本和 CSS

发布于 2024-08-19 06:52:23 字数 430 浏览 2 评论 0原文

我正在我的应用程序中实现这个库,GZip 将您网站的 HTML/CSS/脚本压缩为代码

如果我在 Visual Studio 中运行该网站,它会运行得很好但是当我编译网站并在 IIS 中发布时,它只会 gzip ASPX 文件,而不是 CSS 或 JavaScript 文件。

有没有更好的方法在与 Visual Studio 2005 相对应的 C# 中实现 JavaScript 和 CSS gzip(更改 IIS 不是一个选项,因为它必须在代码中)。

I am implementing this library in my application, GZip compress your website's HTML/CSS/Script in code.

It Works very well if I run the site in Visual Studio, but when I compile my site and publish in IIS it only gzip ASPX files, not CSS or JavaScript files.

Is there a better way for implementing JavaScript and CSS gzip in C# corresponding to Visual Studio 2005 (changing the IIS is not an option as it has to be in the code).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灰色世界里的红玫瑰 2024-08-26 06:52:23

首先,您需要创建一个 HttpHandler 来处理它:

namespace com.waynehartman.util.web.handlers
{
    [WebService(Namespace = "http://waynehartman.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class HttpCompressor : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            // Code for compressing the file and writing it to the HttpResponse
        }
        public bool IsReusable
        {
            get { return true; }
        }
    }
}

然后您需要在 web.config 中添加处理程序映射:

<configuration>
    <system.web>
        <httpHandlers>
            <add verb="*" path="*.css" 
                type="com.waynehartman.util.web.handlers.HttpCompressor, WayneHartmanUtilitiesLibrary"/>
            <add verb="*" path="*.js" 
                type="com.waynehartman.util.web.handlers.HttpCompressor, WayneHartmanUtilitiesLibrary"/>
        </httpHandlers>
    </system.web>
</configuration>

First, you need to create an HttpHandler for processing it:

namespace com.waynehartman.util.web.handlers
{
    [WebService(Namespace = "http://waynehartman.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class HttpCompressor : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            // Code for compressing the file and writing it to the HttpResponse
        }
        public bool IsReusable
        {
            get { return true; }
        }
    }
}

Then you need to add a handler mapping in your web.config:

<configuration>
    <system.web>
        <httpHandlers>
            <add verb="*" path="*.css" 
                type="com.waynehartman.util.web.handlers.HttpCompressor, WayneHartmanUtilitiesLibrary"/>
            <add verb="*" path="*.js" 
                type="com.waynehartman.util.web.handlers.HttpCompressor, WayneHartmanUtilitiesLibrary"/>
        </httpHandlers>
    </system.web>
</configuration>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文