IIS和静态内容? [英] IIS and Static content?

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

问题描述

据<一个href=\"https://books.google.com/books?id=aIs8drBVdaoC&lpg=PA63&ots=BMvOxuwGIm&dq=%22Files%20that%20the%20browser%20retrieves%20from%20the%20server%20should%20be%20stored%20in%20the%20browser%E2%80%99s%20cache%20as%20long%20as%20possible%20to%20help%20minimize%20server%20round-trips.%22&pg=PA63&redir_esc=y#v=onepage&q=%22Files%20that%20the%20browser%20retrieves%20from%20the%20server%20should%20be%20stored%20in%20the%20browser%E2%80%99s%20cache%20as%20long%20as%20possible%20to%20help%20minimize%20server%20round-trips.%22&f=false\">Ultra-Fast ASP.NET:第3章 - 缓存


  

文件,该浏览器从服务器检索应存储在
  浏览器的缓存尽可能长的时间,以帮助减少服务器
  往返。



  • 但如何IIS知道什么是的的静态内容的其实是不是?

    难道仅仅是图片,CSS,JS的而不是的ASPX,ASHX ...?

    其中,的我可以在IIS中看到已经被认为是的静态的什么的不是的?


  • 在哪里页面已被宣布与&LT的场景是什么;%@的OutputCache 头(不包括位置)?是图片里面的CSS JS 源文件它的的相同性质的缓存正在输出?


  • 作为最佳实践,我应该规定了一年到未来作为最大到期时间。我应该使用作为默认网站

  • 在所有静态内容

所以我这样做:

但后来,经过pressing 确定,我的无法找到任何的汇总菜单,显示我:给谁的我已经把一个响应头(在这种情况下:在 CSS 文件夹)。

目前的,为了看到 CSS 文件夹已被施加响应头 - 我得去给 CSS 文件夹中的再次 - &GT; HTTP响应标题 - &GT; 设置公用集 - &GT; ,然后我看到了。它不是写在web.config中。

的如果我去做了一个文件(的Login.aspx 为例):我看到它在web.config中:

 &LT;结构&gt;
    &LT;位置路径=的Login.aspx&GT;
        &LT; system.webServer&GT;
            &LT; staticContent&GT;
                &LT; clientCache cacheControlMode =UseExpirescacheControlMaxAge =1.00:00:00httpExpires =星期五,2013年2月15日00:00:00 GMT/&GT;
            &LT; / staticContent&GT;
        &LT; /system.webServer>
    &LT; /地点&gt;
&LT; /结构&gt;


解决方案

我理解你的处境。有时它混淆IIS如何处理的文件。它也有不同的IIS 6 VS IIS 7和经典的应用程序池和集成模式的应用程序池不同。我的经验主要是与IIS 7.5集成的应用程序池,因此多数民众赞成环境我可以最准确地评论。

首先提问


  

但IIS如何做知道实际上是一个静态的内容,什么是
  不呢?


  
  

难道仅仅是图像,CSS,JS,而不是ASPX,ASHX ...?


  
  

我在哪里可以在哪些已经被认为是静态和IIS看
  什么不可以?


您可以通过导航到你的网站检查在IIS中的文件处理程序的列表,然后单击处理程序映射。默认情况下,这些是从.NET基的web.config这是在不同的位置取决于你的.NET Framework版本继承。


  • C:\\ WINDOWS \\ Microsoft.NET \\框架\\ V2.0.50727 \\ CONFIG \\ web.config中

  • C:\\ WINDOWS \\ Microsoft.NET \\框架\\ v4.0.30319 \\ CONFIG \\ web.config中

如果被请求的文件是不是已经明确地映射到它属于一个包罗万象的处理程序( * )作为最后一个选项( System.Web.DefaultHttpHandler )决定,如果它是一个静态文件或目录浏览请求。因此,静态文件只是文件未绑定到另一个处理程序了。比如你会看到 *。ASPX 已被映射到 System.Web.UI.PageHandlerFactory 之前,这默认的处理程序。因此,它要通过处理程序处理,而不是被认为是一个静态文件。如果删除该映射,你可以在技术上成为*的.aspx作为一个静态文件,如果你真的想(只是它是如何工作的证明)。

但是你也可以明确地在你的web.config的HttpHandlers的部分添加条目的文件扩展名映射到 System.Web.StaticFileHandler 列表中选择文件类型为静态文件在IIS。例如:

 &LT;结构&gt;
  &LT; system.webServer&GT;
    &LT;&处理GT;
      &LT;添加名称=StaticHandler动词=*路径=*拉链。TYPE =System.Web.StaticFileHandlerpreCondition =integratedMode/&GT;
    &LT; /处理器&GT;
  &LT; /system.webServer>
&LT; /结构&gt;

本例是使用&LT; system.webServer&GT; 配置部分,所以它的一个应用程序池在综合模式运行

第二个问题


  

在哪里页面已经被宣布以&lt场景是什么;%@
  的OutputCache头(无位置)。做图像,CSS,JS SRC
  它里面的文件,也被输出缓存与同
  属性?


没有。由于该页面被服务器作为一个单独的请求(甚至由一个单独的处理器),它可以有完全不同的缓存头/提示。主机页面,它可以使用的资源不是从缓存的角度有关。

在事实上你甚至可能想为*。html的一个较短的缓存期限和较长的缓存期* .jpg或* .PNG?要考虑的事情。

第三题


  

作为最佳prcatice,我应该规定了一年到未来的
  最大呼气再寄一次应该使用作为默认为所有
  网站上的静态内容


嗯...我可能不会走得太远,因为一年。如何约一个月?我会成立一个全球性的政策是这样的:

 &LT;结构&gt;
  &LT; system.webServer&GT;
    &LT; staticContent&GT;
      &LT;! - 设置过期头为静态含量30天 - &GT;
      &所述; clientCache cacheControlMode =UseMaxAgecacheControlMaxAge =30.00:00:00/&GT;
    &LT; / staticContent&GT;
  &LT; /system.webServer>
&LT; /结构&gt;

这是一样的,你上面显示样品,而不是在&LT;地点&gt; 元素,取而代之的则是对根&LT;结构&gt; 元素,所以它是默认的策略。再次,这是一个应用程序池在集成模式下运行即可。有时候你还需要打开:

 &LT;结构&gt;
    &LT; system.webServer&GT;
        &LT;模块runAllManagedModulesForAllRequests =真正的&GT;
            &LT;! - 东西 - &GT;
        &LT; /模块&gt;
    &LT; /system.webServer>
&LT; system.webServer&GT;

这只是确保静态文件是通过尊重上面的配置元素的托管静态文件处理程序进行处理。

编辑地址评论

你上面贴的配置对话框中的文档位于:配置HTTP过期响应头(IIS 7)

显然,这些设置保存在 C:\\ WINDOWS \\ SYSTEM32 \\ INETSRV \\设置\\的applicationHost.config

我没有IIS7和个人发展上的IIS 7.5的现在。所以,请发表评论,如果您可以验证这个位置是正确的!

According to Ultra-Fast ASP.NET: Chapter 3 - Caching:

Files that the browser retrieves from the server should be stored in the browser’s cache as long as possible to help minimize server round-trips.

  • But how does IIS know what a static content actually is and is not?

    Is it just images, CSS, JS and not ASPX, ashx...?

    Where can I see in IIS what is already considered to be static and what is not ?

  • What about the scenario where a page has been declared with <%@ OutputCache header (without location)? Are the images, CSS and JS source files inside of it also being output cached with the same properties?

  • As a best practice, I should set one year into the future as the maximum expiration time. I should use that as the default for all static content on the site

So I did this :

But later, after pressing OK, I can't find any summary menu which shows me: to whom I already put a response header (in this case: the css folder).

Currently, in order to see that css folder has been applied with response headers - I have to go to the css folder again --> Http Response Header-->Set Common Headers --> and then I see it. It isn't written in the web.config.

But if I do it for a file (Login.aspx for example): I do see it in web.config:

<configuration>
    <location path="Login.aspx">
        <system.webServer>
            <staticContent>
                <clientCache cacheControlMode="UseExpires" cacheControlMaxAge="1.00:00:00" httpExpires="Fri, 15 Feb 2013 00:00:00 GMT" />
            </staticContent>
        </system.webServer>
    </location>
</configuration>

解决方案

I understand your situation. Sometime its confusing how IIS handles a file. Its also different for IIS 6 vs IIS 7 and different for Classic App Pools and Integrated mode app pools. My experience is mostly with Integrated App Pools on IIS 7.5, so thats the environment I can comment on most accurately.

First Question

But how does IIS knows what is actually a static content and what is not?

Is it just images , css , js and not ASPX , ashx...?

Where can I see in the IIS what is already considered to be static and what not ?

You can inspect the list of file handlers in IIS by navigating to your website and then click 'Handler Mappings'. By default these are inherited from the .Net base web.config which is in a different location depending on your .Net framework version.

  • C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config
  • C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config

If a file being requested isn't already explicitly mapped to another handler it falls to a catch all handler (*) as the last option (System.Web.DefaultHttpHandler) which determines if it is a static file or a directory browsing request. So Static files are simply files not bound to another handler already. For example you'll see that *.aspx is already mapped to System.Web.UI.PageHandlerFactory prior to this default handler. So its going to be processed by that handler and not be considered a static file. If you removed that mapping you could technically serve *.aspx as a static file if you really wanted to (just for proof of how it works).

But you can also explicitly list a file type as a static file by adding an entry in your web.config's httpHandlers section mapping the file extensions to System.Web.StaticFileHandler in IIS. For example:

<configuration>
  <system.webServer>
    <handlers>
      <add name="StaticHandler" verb="*" path="*.zip" type="System.Web.StaticFileHandler" preCondition="integratedMode" />
    </handlers>
  </system.webServer>
</configuration>

This example is using the <system.webServer> config section, so its for an App Pool running in Integrated Mode.

Second Question

What about the scenario where a page has been declared with <%@ OutputCache header(without location) . does the images,css,js src files inside of it , are also being output cached with the same properties?

No. Because the page is being server as a separate request (maybe even by a separate handler) it can have totally different cache headers/hints. The host page and the resources it may use are not related from a caching perspective.

In fact you may even want to have a shorter cache period for *.html and a longer cache period for *.jpg or *.png? Something to consider.

Third Question

As a best prcatice , I should set one year into the future as the maximum expiration time.I should use that as the default for all static content on the site

Hmm... I might not go as far as one year. How about one month? I would set a global policy like this:

<configuration>
  <system.webServer>
    <staticContent>
      <!-- Set expire headers to 30 days for static content-->
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
    </staticContent>
  </system.webServer>
</configuration>

This is the same as the sample you showed above, but is not inside a <location> element, instead it is right in the root <configuration> element so it is the default policy. Again this is for an App Pool running in Integrated Mode. Sometimes you also need to turn on:

<configuration>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
            <!-- stuff -->
        </modules>
    </system.webServer>
<system.webServer>

This just makes sure that static files are processed through the managed static file handler which respects the above configuration elements.

Edit to Address Comments

The documentation for the configuration dialog you posted above is located here: Configure the HTTP Expires Response Header (IIS 7)

Apparently these settings are saved in C:\Windows\System32\inetsrv\config\applicationHost.config

I do not have IIS7 and personally develop on IIS 7.5 now. So please post a comment if you can verify this location is accurate!

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

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