IIS understand static files in MVC as dynamic content

女生的网名这么多〃 提交于 2019-12-05 08:23:26

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

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

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.

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

You can enable dynamic compression on a per-folder basis, from IIS Manager. Click on the folder name first in the Connections pane, then double-click on the Compression icon in the center pane, and select Enable dynamic compression.

Or, here's another, more brute force way:

Edit C:\Windows\System32\inetsrv\config\applicationHost.config (the IIS config file; make a copy first).

In the httpCompression section, remove the lines with mimeType="/" and mimeType="text/*", and replace them with mimeType="text/css" (an entry for JS is already there).

After re-starting IIS, dynamic compression should only be applied to your CSS & JS files, not your aspx output (which is text/html).

<modules runAllManagedModulesForAllRequests="true" />

is not required any more for IIS 7.5 SP1 or IIS7 SP1. It was required for MVC so requests to extensionless url go through the asp.net pipeline.

Extensionless url support is new in IIS7 SP1 and IIS7.5 SP1. It is available for IIS7 as a patch that you have to request and install. You will find it here with complete answers to your questions: http://support.microsoft.com/kb/980368

In IIS config, check "mapping manager", "path" column. Maybe you have a mapping setup for these files. Also check the * path with StaticFileHandler.

Did you remove any handler in your web.config ? Maybe by adding a statement ?

It should help (IIS7 MVC3):

Add another mapper to your 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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!