配置的ETag在asp.net HTTP模块 [英] Configuring ETags with Http module in asp.net

查看:140
本文介绍了配置的ETag在asp.net HTTP模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在优化我们的公司网站与搜索引擎优化和YSlow的。
但在YSlow的的ETag是F。
我已经通过数万网站和教程,最好的选择是使用一个HTTP模块不见了。
我这样做,并试图几大模块,但没有显示在语法results.maybe什么是错的,否则我注册错了。有的说,这是最好的,而不是使用,因为堆崩溃preSendRequestHeaders app_PostReleaseRequestState。我一直没有结果同时使用。
这里是 :
文件名是ETAG,它是在APP-code文件夹

i'm optimizing our company web site with seo optimization and yslow. but in yslow the ETAGS are F . I've gone through tens of web sites and tutorials and the best option was using an HTTP Module. I've done so and tried several modules but none shows results.maybe something in syntax is wrong or i'm registering it wrong .some say it is best to use app_PostReleaseRequestState instead of OnPreSendRequestHeaders because of a crash in heap.I've used both with no results. here it is : the file name is etag and it is in app-code folder

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>

和这里是code:

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");
        //}
    }

谢谢您的回答。

推荐答案

首先,你可以删除您服务器的标签!而不是让他一次又一次把它,然后你删除它。

First you can remove the server tags in your server ! and not let him place it again and again and you then remove it.

您可以做,即使在使用你的web.config的 customHeaders

You can do that even on your web.config using the customHeaders:

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

的eTag或实体标签是办法国旗的页面,然后看看你的code。如果页面已经改变,必须更新。如果你看到的ETag那么你的code的某些部分增加了对这样的检查,我认为你必须离开它,因为它是因为你打破了计划的这一逻辑。

The ETag or entity tag is way to flag a page and then see on your code if the page have been change and need to be update. If you see the ETag then some part of your code is added for this check and I think that you must left it as it is because you break this logic of the program.

如果这是ETag的地方通过服务器来标记的图像或类似的项目,您可以通过添加静态内容是现场更避免大多数这个标签,而这也可以在IIS上进行,或者在web.config中的。

If this ETag is places by server to flag images or similar items, you can avoid most of this tag by adding the static content be live more, and this is also can be done on iis, or on web.config as.

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

所以我认为你所做的模块是没有必要为这个想。

So I think that the module that you made is not necessary for this thinks.

这篇关于配置的ETag在asp.net HTTP模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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