我正在通过 seo 优化和 yslow 来优化我们公司的网站。
但在 yslow 中,ETAGS 是 F 。
我浏览了数十个网站和教程,最好的选择是使用 HTTP 模块。
我已经这样做并尝试了几个模块,但没有显示结果。也许语法中的某些内容是错误的,或者我注册错误。有人说最好使用 app_PostReleaseRequestState 而不是 OnPreSendRequestHeaders 因为堆中崩溃。我使用过两者都没有结果。
这里是 :
文件名为 etag,位于 app-code 文件夹中
网络配置:
<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");
//}
}
感谢您的回答。
首先,您可以删除服务器中的服务器标签!不要让他一次又一次地放置它,然后你将其移除。
您甚至可以在 web.config 上使用customHeaders
:
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
<remove name="X-UA-Compatible" />
<remove name="ETag" />
</customHeaders>
</httpProtocol>
ETag 或实体标签是标记页面然后在代码中查看页面是否已更改且需要更新的方法。如果您看到 ETag,那么您的代码的某些部分将被添加用于此检查,我认为您必须保持原样,因为您破坏了程序的这种逻辑。
如果服务器放置此标签来标记图像或类似项目,您可以通过添加更多的静态内容来避免大多数此标签,这也可以在 iis 或 web.config 上完成。
<staticContent>
<clientCache cacheControlMaxAge ="8.00:00:00" cacheControlMode="UseMaxAge" />
</staticContent>
所以我认为你制作的模块对于这个想法来说是不必要的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)