IIS了解MVC静态文件动态内容 [英] IIS understand static files in MVC as dynamic content

查看:193
本文介绍了IIS了解MVC静态文件动态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与httpCom pression我relalized的IIS了解MVC静态文件动态内容,所以即使您选择了启用静态内容融为一体pression ,但玩别T嘀启用动态内容融为一体pression ,IIS将返回的.css 的.js 无COM pression文件:

Playing with the httpCompression I relalized that IIS understand static files in MVC as dynamic content, so even if you tick the "Enable static content compression", but don't tick "Enable dynamic content compression", IIS will return the .css and .js files without compression:

GET /MVCX/Content/Site.css HTTP/1.1
Host: localhost
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2
Accept: text/css,*/*;
Referer: http://localhost/mvcx/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

HTTP/1.1 200 OK
Content-Type: text/css
Last-Modified: Mon, 05 Dec 2011 12:42:37 GMT
Accept-Ranges: bytes
ETag: "c79895e4bb3cc1:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Mon, 05 Dec 2011 12:44:43 GMT
Content-Length: 1005

不过,如果我勾选启用动态内容融为一体pression 的文件是COM pressed:

But then if I tick the "Enable dynamic content compression" the files are compressed:

GET /MVCX/Content/Site.css HTTP/1.1
Host: localhost
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2
Accept: text/css,*/*;
Referer: http://localhost/mvcx/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

HTTP/1.1 200 OK
Content-Type: text/css
Content-Encoding: gzip
Last-Modified: Mon, 05 Dec 2011 12:42:37 GMT
Accept-Ranges: bytes
ETag: "c79895e4bb3cc1:0"
Vary: Accept-Encoding
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Mon, 05 Dec 2011 12:48:36 GMT
Content-Length: 522

即使我试图忽略到〜/内容〜/脚本的路线,这些文件仍理解为动态内容:

Even if I try to ignore the routes to ~/Content and ~/Scripts, these files are still understood as dynamic content:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("{Content}/{*pathInfo}");
        routes.IgnoreRoute("{Scripts}/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );
    }

我想这大概是因为需要对MVC也是web.config行通过ASP.NET管道迫使所有的请求:

I think this is probably because the web.config line that is needed for MVC but also forces all the request through the ASP.NET pipeline:

<modules runAllManagedModulesForAllRequests="true" />

更新:我试图把这个设置为false,并发生在同一个

UPDATE: I have tried to put this setting to false and happens the same.

有没有办法避免呢?我不想COM pression我的动态内容,但我想为我的静态内容。

Is there a way to avoid it? I don't want compression for my dynamic content but I do want it for my static content.

或者是把文件别处的唯一途径?

Or is the only way put the files somewhere else?

干杯。

推荐答案

我想你会发现里克已经回答了你的问题在​​这里:

I think you'll find Rick has already answered your question here:

http://www.west-wind.com/weblog/posts/2011/May/05/Builtin-GZipDeflate-Com$p$pssion-on-IIS-7x

我不知道为什么你这个问题是诚实的。静态的COM pression正在开箱即用,我在MVC3,没有特殊的变化需要。

I'm not sure why you are having that issue to be honest. Static Compression is working out of the box for me in MVC3, no special changes needed.

像RickNZ说,要确保MIME类型占了正确的对ApplicationHost.config

Like RickNZ said, make sure the mime types are accounted for properly in applicationhost.config.

这篇关于IIS了解MVC静态文件动态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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