需求:在IIS 7、7.5、8.0、8.5和ASP.NET中刪除HTTP響應標頭,修改或隱藏IIS 7、7.5、8.0、8.5的Server頭信息。
解決方案:使用url-rewrite規則
1、先安裝 http://www.iis.net/downloads/microsoft/url-rewrite
2、把下面復制到web.config
1
2
3
4
5
6
7
8
|
<rewrite> <outboundRules rewriteBeforeCache="true"> <rule name="Remove Server header"> <match serverVariable="RESPONSE_Server" pattern=".+" /> <action type="Rewrite" value="Apache" /> </rule> </outboundRules> </rewrite> |
注意 ,這為返回的Server協議頭,value按需求修改。
3、重啟IIS
如果上面的操作不行可以參考下面的文章
刪除X-Powered-By HTTP頭
IIS7中移除X-Powered-By HTTP頭的方法是:
1 啟動IIS Manager
2 點擊計算機名
3 選擇你需要修改的站點并 雙擊 HTTP響應頭部分
4 所有的自定義HTTP頭全在這里了,刪除相應的頭僅需要點擊右邊的 Remove 按鈕
刪除X-AspNet-Version HTTP頭
修改web.config配置文件 在 <system.web> 塊內添加下面這行
<httpRuntime enableVersionHeader="false" />
刪除X-AspNetMvc-Version HTTP頭
在Global.asax的Application_Start事件中將MvcHandler類的DisableMvcResponseHeader屬性設置為True
MvcHandler.DisableMvcResponseHeader = True
刪除Server HTTP頭
下載UrlScan
Download the setup MSI file for UrlScan 3.1 from one of the following URLs to your computer:
x86: http://www.microsoft.com/downloads/details.aspx?FamilyID=ee41818f-3363-4e24-9940-321603531989
x64: http://www.microsoft.com/downloads/details.aspx?FamilyID=361e5598-c1bd-46b8-b3e7-3980e8bdf0de
安裝UrlScan(需要安裝IIS-Metabase,即IIS 6 元數據庫兼容性組件)后,
修改 C:\Windows\System32\inetsrv\urlscan\UrlScan.ini 文件,設置 RemoveServerHeader=1
然后重啟IIS
好了這篇文章就介紹到這了,希望大家以后多多支持服務器之家。
原文鏈接:https://blog.csdn.net/hx7013/article/details/79786563