Configuring ETags with Http module in asp.net

I am optimizing our company website with SEO and yslow optimization. but in yslow ETAGS - F. I went through dozens of websites and tutorials and the best option was to use the HTTP module. I did this and tried several modules but none of them showed any results. Maybe something in the syntax is wrong or I am registering it incorrectly. Let's say it's better to use app_PostReleaseRequestState instead of OnPreSendRequestHeaders due to a heap failure. both with no results. here: the filename is this and it is in the code folder

web config:

<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>

      

and here is the 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");
        //}
    }

      

Thank you for your responses.

+2


source to share


1 answer


First you can remove the server tags on your server! and don't let it post it over and over and then delete it.

You can even do this in your web.config using customHeaders

:

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

      

An ETag or object is a way to mark a page and then view the code if the page has changed and needs to be refreshed.If you see an ETag then some of your code is added for this check and I think you should leave it as it is because you are breaking this program logic.



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

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

      

So, I think the module you created is not needed for this.

+2


source







All Articles