{"id":1005,"date":"2018-11-21T14:37:26","date_gmt":"2018-11-21T14:37:26","guid":{"rendered":"http:\/\/www.netexl.com\/blog\/?p=1005"},"modified":"2026-04-02T09:47:36","modified_gmt":"2026-04-02T09:47:36","slug":"configure-options-to-secure-asp-net-application","status":"publish","type":"post","link":"https:\/\/www.netexl.com\/blog\/configure-options-to-secure-asp-net-application\/","title":{"rendered":"Configuration Options to Secure ASP.NET Application"},"content":{"rendered":"<p>If you have ASP.NET website on internet,\u00a0you must make sure\u00a0to implement following cofiguration steps to secure your website.<\/p>\n<p><strong>Block libwww-perl attack in ASP.NET Application hosted in IIS<\/strong> &#8211; Follow <a href=\"https:\/\/www.netexl.com\/blog\/block-libwww-perl-attack-in-asp-net-application-hosted-in-iis\/\" target=\"_blank\">this article<\/a> to configure this.<\/p>\n<p>Some response headers\u00a0reveal technical details about the server which\u00a0must be\u00a0removed. For example a sample response from an ASP.Net application may look like this<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1006\" src=\"https:\/\/www.netexl.com\/blog\/wp-content\/uploads\/2018\/11\/ASPNetResponse.png\" alt=\"\" width=\"649\" height=\"169\" srcset=\"https:\/\/www.netexl.com\/blog\/wp-content\/uploads\/2018\/11\/ASPNetResponse.png 649w, https:\/\/www.netexl.com\/blog\/wp-content\/uploads\/2018\/11\/ASPNetResponse-300x78.png 300w, https:\/\/www.netexl.com\/blog\/wp-content\/uploads\/2018\/11\/ASPNetResponse-280x73.png 280w\" sizes=\"auto, (max-width: 649px) 100vw, 649px\" \/><\/p>\n<p>In this response &#8220;Server&#8221;, &#8220;X-AspNet-Version&#8221;, &#8220;X-Powered-By&#8221; headers are revealing technical details about the server. We can\u00a0remove these\u00a0unnecessary IIS response headers as following<\/p>\n<p><strong>Remove &#8220;X-Powered-By&#8221; Header<\/strong> &#8211; Open web.config and\u00a0check for\u00a0customHeaders tag. If this is not already there, then add it as child of &#8220;&lt;httpProtocol&gt;&#8221; and add &#8220;remove&#8221; entry for X-Powered-By as shown below<\/p>\n<pre class=\"lang:default decode:true\">&lt;configuration&gt;\r\n  &lt;system.webServer&gt;\r\n    &lt;httpProtocol&gt;\r\n\t\t&lt;customHeaders&gt;\r\n\t\t\t&lt;remove name=\"X-Powered-By\" \/&gt;\r\n\t\t&lt;\/customHeaders&gt;\r\n    &lt;\/httpProtocol&gt;\t \r\n  &lt;\/system.webServer&gt;\r\n&lt;\/configuration&gt;<\/pre>\n<p>You should also check the response from your\u00a0Asp.Net application if this is using a shared hosting which may add additional server specific information to response headers. Add remove entry for all such headers in your web.config.<\/p>\n<p><strong>Remove &#8220;X-AspNet-Version&#8221; Header<\/strong> &#8211; In web.config file look for\u00a0&lt;httpRuntime&gt; under &lt;system.web&gt;.\u00a0 Add enableVersionHeader attribute and set its value to false.<\/p>\n<pre class=\"lang:default decode:true\">&lt;httpRuntime targetFramework=\"4.5\" enableVersionHeader=\"false\" \/&gt;\r\n<\/pre>\n<p><strong>Remove &#8220;Server&#8221; Header<\/strong> &#8211;\u00a0Add following line in\u00a0Application_BeginRequest\u00a0 method of Global.asax.cs<\/p>\n<pre class=\"lang:default decode:true \">protected void Application_BeginRequest(object sender, EventArgs e)\r\n{\r\n    HttpContext.Current.Response.Headers.Remove(\"Server\");\r\n}<\/pre>\n<p><strong>Add Security Headers in Response<\/strong> &#8211; Add additional security headers (<a href=\"https:\/\/infosec.mozilla.org\/guidelines\/web_security#x-content-type-options\" target=\"_blank\">X-Content-Type-Options<\/a>, <a href=\"https:\/\/infosec.mozilla.org\/guidelines\/web_security#x-frame-options\" target=\"_blank\">X-Frame-Options<\/a>, <a href=\"https:\/\/infosec.mozilla.org\/guidelines\/web_security#x-xss-protection\" target=\"_blank\">X-XSS-Protection<\/a>) in response to harden security of the application. Add entries in web.config as following<\/p>\n<pre class=\"lang:default decode:true\">&lt;customHeaders&gt;\r\n\t&lt;remove name=\"X-Powered-By\" \/&gt;\r\n    &lt;add name=\"X-Frame-Options\" value=\"DENY\" \/&gt; \r\n    &lt;add name=\"X-XSS-Protection\" value=\"1; mode=block\" \/&gt; \r\n    &lt;add name=\"X-Content-Type-Options\" value=\"nosniff \" \/&gt;     \r\n&lt;\/customHeaders&gt;\r\n<\/pre>\n<p>If you are using iFrames in your website, you can set value of &#8220;X-Frame-Options&#8221; to &#8220;SAMEORIGIN&#8221;.<\/p>\n<p>After implementing these, check the response headers in browser developer console of your liking.\u00a0You can also use a third-party service such as\u00a0<a href=\"https:\/\/securityheaders.com\" target=\"_blank\">https:\/\/securityheaders.com<\/a> to quickly check\u00a0whether or not\u00a0 security headers are returned correctly from your website. The scan\u00a0may propose additional security headers for your website which you can implement if\u00a0need be.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have ASP.NET website on internet,\u00a0you must make sure\u00a0to implement following cofiguration steps to secure your website. Block libwww-perl attack in ASP.NET Application hosted in IIS &#8211; Follow this article to configure this. Some response headers\u00a0reveal technical details about the server which\u00a0must be\u00a0removed. For example a sample response from an ASP.Net application may look like this In this response &#8220;Server&#8221;, &#8220;X-AspNet-Version&#8221;, &#8220;X-Powered-By&#8221; headers are revealing technical details about the server. We can\u00a0remove these\u00a0unnecessary IIS response headers as following Remove &#8220;X-Powered-By&#8221; Header &#8211; Open web.config and\u00a0check for\u00a0customHeaders tag. If this is not already there, then add it as child of &#8220;&lt;httpProtocol&gt;&#8221; and add &#8220;remove&#8221; entry for X-Powered-By as shown below &lt;configuration&gt; &lt;system.webServer&gt; &lt;httpProtocol&gt; &lt;customHeaders&gt; &lt;remove name=&#8221;X-Powered-By&#8221; \/&gt; &lt;\/customHeaders&gt; &lt;\/httpProtocol&gt; &lt;\/system.webServer&gt; &lt;\/configuration&gt; You should also check the response from your\u00a0Asp.Net application if this is using a shared hosting which may add additional server specific information to response headers. Add remove entry[&#8230;]<\/p>\n","protected":false},"author":5,"featured_media":1547,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1005","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-asp-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/posts\/1005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/comments?post=1005"}],"version-history":[{"count":4,"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/posts\/1005\/revisions"}],"predecessor-version":[{"id":1016,"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/posts\/1005\/revisions\/1016"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/media\/1547"}],"wp:attachment":[{"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/media?parent=1005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/categories?post=1005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/tags?post=1005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}