2012-07-09 30 views
2

我正在使用seo優化和yslow優化我們公司的網站。 但在伊斯洛的ETAGS是F. 我已經經歷了數十個網站和教程,最好的選擇是使用HTTP模塊。 我已經這樣做了,並嘗試了幾個模塊,但沒有顯示results.maybe語法的東西是錯誤的或我註冊它錯了。有人說,最好使用app_PostReleaseRequestState而不是OnPreSendRequestHeaders,因爲在堆中崩潰。我是兩者都沒有結果。 那就是: 文件名是ETAG,它是在應用程序代碼文件夾在asp.net中使用Http模塊配置ETags

web配置:

<system.webServer> 
     <modules runAllManagedModulesForAllRequests="true"> 
     <add type="CompressionModule" name="CompressionModule"/> 
      <add type="ETags" name="ETags"/> 
     <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 
     </modules> 
    </system.webServer> 

這裏是代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
/// <summary> 
/// Summary description for ETags 
/// </summary> 

    public class ETags : IHttpModule 
    { 
     public void Dispose() { } 
     public void Init(HttpApplication app) 
     { 
      app.PostReleaseRequestState += new EventHandler(app_PostReleaseRequestState); 

     } 
     void app_PostReleaseRequestState(object sender, EventArgs e) 
     { 
      HttpContext.Current.Response.Headers.Remove("ETag"); 
      HttpContext.Current.Response.Headers.Remove("Server"); 
      HttpContext.Current.Response.Headers.Remove("X-AspNet-Version"); 
      HttpContext.Current.Response.Headers.Remove("X-Powered-By"); 
     } 
     //public void Init(HttpApplication context) 
     //{ 
     // context.PreSendRequestHeaders += OnPreSendRequestHeaders; 
     //} 

     //void OnPreSendRequestHeaders(object sender, EventArgs e) 
     //{ 
     // HttpContext.Current.Response.Headers.Remove("ETag"); 
     // HttpContext.Current.Response.Headers.Remove("Server"); 
     // HttpContext.Current.Response.Headers.Remove("X-AspNet-Version"); 
     // HttpContext.Current.Response.Headers.Remove("X-Powered-By"); 
     //} 
    } 

謝謝您的回答。

回答

2

首先,您可以刪除服務器中的服務器標籤!不要讓他一次又一次地放置它,然後你將它移除。

你可以做到這一點甚至在你的web.config使用customHeaders

<httpProtocol> 
    <customHeaders> 
     <remove name="X-Powered-By" /> 
     <remove name="X-UA-Compatible" /> 
     <remove name="ETag" /> 
    </customHeaders> 
</httpProtocol>   

The ETag or entity tag的方式來標誌一個頁面,然後在你的代碼中看到,如果頁面已經改變,必須更新。如果你看到ETag,那麼你的代碼的一部分被添加進這個檢查中,我認爲你必須保持原樣,因爲你打破了這個程序的邏輯。

如果這個ETag是由服務器放置標誌圖片或類似項目的地方,你可以通過添加靜態內容來避免大部分標籤被活得更多,這也可以在iis上完成,或者在web.config上完成。

<staticContent> 
    <clientCache cacheControlMaxAge ="8.00:00:00" cacheControlMode="UseMaxAge" /> 
</staticContent> 

所以我認爲你所做的模塊並不需要這樣認爲。

+0

嗨感謝的建議,但:1,我加你的HTTP的Web配置並沒有什麼。這協議是從微軟的網站分析標題:內容編碼: 的Content-Length:7103 緩存控制:私人 內容 - 類型:text/html; charset = utf-8 Date:Mon,09 Jul 2012 13:50:17 GMT X-AspNet-Version:4.0.30319 2。 ETAGs仍然在那裏檢查你自己[鏈接](http://imi5.com)3.第二個(靜態內容被分離地添加到所有子內容的子內容) – 2012-07-09 12:53:40

+0

@imijan但什麼? – Aristos 2012-07-09 12:55:39

+0

i'gonna發佈了一些鏈接,指向其他人如何解決問題 – 2012-07-09 13:11:40