Removing redundant response headers in ASP.

Source: Internet
Author: User

This article mainly describes how to optimize the unnecessary information in the response header when ASP. NET MVC uses IIS

By default, creating an ASP. NET MVC project will contain sensitive information in the response header, which is useless but exposes configuration information for IIS.

The following is the default response header information:

Cache-control:private, s-maxage=0content-encoding:gzipcontent-length:8024content-type:text/html; Charset=utf-8date:fri, Sep 03:17:10 gmtserver:microsoft-iis/10.0vary:accept-encodingx-aspnet-version : 4.0.30319x-aspnetmvc-version:5.2x-frame-options:sameoriginx-powered-by:asp. Netx-sourcefiles:=? UTF-8? B? rdpcv29ya1wymde2xe56tmquswrlbnrpdhlcr0xelldlylxtdxblclxvc2vycw==?=

In the above content, the red part is not the information that must be output, but will expose some configuration information of the server, and the following describes how to remove the unnecessary output information:

    • X-aspnetmvc-version

Open Global.asax.cs, and in the Application_Start method, add the following code:

true;

    • Server

Also in Global.asax.cs , add the following code

protected void Application_presendrequestheaders (object sender, EventArgs e) {as     HttpApplication;    if null &&        null)    {        app. Context.Response.Headers.Remove ("Server");}    }

    • X-aspnet-version

Locate the system.web node in the Web. config file and add the following configuration:

"false" />

    • X-powered-by

Locate System.webservice in the Web. config file and add the following configuration:

"x-powered-by" />  </ Customheaders>

OK, finish the above operation, after compiling, open, F12 can see,Response header content as follows :

Cache-control:private, s-maxage=0content-encoding:gzipcontent-length:8018content-type:text/html; Charset=utf-8date:fri, 02:35:39 gmtvary:accept-encodingx-frame-options:sameoriginx-sourcefiles:=? UTF-8? B? rdpcv29ya1wymde2xe56tmquswrlbnrpdhlcr0xelldlylxtdxblclxvc2vycw==?=

Unnecessary information has been removed. A lot more refreshing!

Removing redundant response headers in ASP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.