6

httpCompression をいじってみると、IIS は MVC の静的ファイルを動的コンテンツとして認識していることがわかったので、「静的コンテンツの圧縮を有効にする」にチェックを入れても、「動的コンテンツの圧縮を有効にする」にチェックを入れなくても、IIS は.cssおよび.jsファイルを圧縮せずに返します。 :

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

しかし、「動的コンテンツの圧縮を有効にする」にチェックを入れると、ファイルは圧縮されます。

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

~/Contentとへのルートを無視しようとしても~/Scripts、これらのファイルは動的コンテンツとして認識されます。

    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 パイプラインを介してすべての要求を強制します。

<modules runAllManagedModulesForAllRequests="true" />

更新: この設定を false にしようとしましたが、同じことが起こります。

それを回避する方法はありますか?動的コンテンツには圧縮は必要ありませんが、静的コンテンツには必要です。

それとも、ファイルを別の場所に置く唯一の方法ですか?

乾杯。

4

4 に答える 4

1

Rick がすでにここであなたの質問に答えていることがわかると思います。

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

正直なところ、なぜその問題を抱えているのかわかりません。静的圧縮は、MVC3 ですぐに使用できます。特別な変更は必要ありません。

RickNZ が言ったように、MIME タイプが で適切に説明されていることを確認してapplicationhost.configください。

于 2011-12-12T21:51:29.327 に答える
0

役立つはずです(IIS7 MVC3):

別のマッパーを web.config に追加します

<system.webServer>
    <modules runAllManagedModulesForAllRequests="false">
...
    </modules>

 <handlers>
      <remove name="UrlRoutingHandler" />     
      <clear />
      <add name="svc-ISAPI-4.0" path="*.svc" verb="*" modules="IsapiModule" scriptProcessor="%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
      <add name="AssemblyResourceLoader-Integrated" path="WebResource.axd" verb="GET,DEBUG" type="System.Web.Handlers.AssemblyResourceLoader" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />
      <add name="svc-Integrated" path="*.svc" verb="*" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" modules="ManagedPipelineHandler" resourceType="Unspecified" requireAccess="Read" preCondition="integratedMode" />
     <add name="StaticFileHandler-html" path="*.html" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read"/>
 ...     
      <add name="StaticFileHandler-css" path="*.css" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
      <add name="StaticFileHandler-js" path="*.js" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
      <add name="wildcard" path="*" verb="GET,HEAD,POST,DEBUG" type="System.Web.UI.PageHandlerFactory" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="integratedMode" responseBufferLimit="4194304" />
      <add name="PageHandlerFactory-Folders" path="*" verb="*" type="System.Web.UI.PageHandlerFactory" modules="ManagedPipelineHandler" resourceType="Unspecified" requireAccess="Read" allowPathInfo="false" preCondition="integratedMode" />
      <add name="StaticFileHandler" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
    </handlers>
于 2012-03-27T16:01:50.220 に答える
0
<modules runAllManagedModulesForAllRequests="true" />

IIS 7.5 SP1 または IIS7 SP1 では不要になりました。拡張子のない URL へのリクエストが asp.net パイプラインを通過するように、MVC に必要でした。

拡張子のない URL のサポートは、IIS7 SP1 および IIS7.5 SP1 で新しく追加されました。IIS7 では、要求してインストールする必要があるパッチとして入手できます。あなたの質問に対する完全な回答がここにあります: http://support.microsoft.com/kb/980368

IIS 構成で、「マッピング マネージャー」、「パス」列を確認します。これらのファイルのマッピングが設定されている可能性があります。また、StaticFileHandler で * パスを確認してください。

web.config でハンドラーを削除しましたか? 多分ステートメントを追加することによって?

于 2011-12-10T22:10:27.363 に答える
0

IIS マネージャーから、フォルダーごとに動的圧縮を有効にすることができます。最初に [接続] ペインでフォルダー名をクリックし、中央のペインで [圧縮] アイコンをダブルクリックして、[動的圧縮を有効にする] を選択します。

または、別のより強引な方法を次に示します。

C:\Windows\System32\inetsrv\config\applicationHost.config (IIS 構成ファイル。最初にコピーを作成) を編集します。

httpCompression セクションで、mimeType=" / " および mimeType="text/*" の行を削除し、mimeType="text/css" に置き換えます (JS のエントリは既に存在します)。

IIS を再起動した後、動的圧縮は CSS および JS ファイルにのみ適用され、aspx 出力 (text/html) には適用されません。

于 2011-12-06T21:54:09.173 に答える