Jak usunąć ASP.Net domyślne nagłówki HTTP MVC?
Każda strona w aplikacji MVC, z którą pracuję, ustawia te nagłówki HTTP w odpowiedziach:
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
X-AspNetMvc-Version: 2.0
Jak zapobiec ich pokazaniu?
11 answers
"powered by" jest niestandardowym nagłówkiem w IIS. Zmiana zależy od używanej wersji usług IIS. Aby dowiedzieć się, jak zmodyfikować lub usunąć, zobacz tutaj:
Http://www.iis.net/ConfigReference/system.webServer/httpProtocol/customHeaders
Aby usunąć nagłówek MVC,
In Global.asax, w zdarzeniu startowym aplikacji:
MvcHandler.DisableMvcResponseHeader = true;
Wrzuć to do sieci.config pozbądź się nagłówka X-AspNet-Version:
<system.web>
<httpRuntime enableVersionHeader="false" />
</system.web>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-16 10:00:18
Możesz je również usunąć, dodając kod do swojej globalnej.plik asax:
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("X-Powered-By");
HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");
HttpContext.Current.Response.Headers.Remove("Server");
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-01-19 18:51:59
Znalazłem tę konfigurację w moim web.config
, która była dla New Web Site...
stworzonego w Visual Studio(w przeciwieństwie do New Project...
). Ponieważ pytanie brzmi a ASP.NET aplikacja MVC, nie jako istotna, ale nadal opcja.
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
</system.webServer>
Update : również Troy Hunt ma artykuł zatytułowany Shhh ... nie pozwól nagłówkom odpowiedzi mówić zbyt głośno ze szczegółowymi krokami usuwania tych nagłówków, a także linkiem do jego asafaweb narzędzie do skanowania ich i innych zabezpieczeń konfiguracje.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-08-10 14:22:03
Jak opisano w maskowanie twojego ASP.NET aplikacja webowa MVC na IIS 7 , możesz wyłączyć nagłówek X-AspNet-Version, stosując następującą sekcję konfiguracji do swojej strony internetowej.config:
<system.web>
<httpRuntime enableVersionHeader="false"/>
</system.web>
I usuń nagłówek X-AspNetMvc-Version zmieniając Twój Globalny.asax.cs jak następuje:
protected void Application_Start()
{
MvcHandler.DisableMvcResponseHeader = true;
}
Jak opisano w niestandardowe nagłówki możesz usunąć nagłówek "X-Powered-By", stosując następującą sekcję konfiguracji do swojej sieci.config:
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
</customHeaders>
</httpProtocol>
</system.webServer>
Jest nie ma łatwego sposobu na usunięcie nagłówka odpowiedzi "Server" poprzez konfigurację, ale możesz zaimplementować HttpModule
, aby usunąć określone nagłówki HTTP, jak opisano w maskowanie ASP.NET aplikacja webowa MVC na IIS 7 i w how-to-remove-server-x-aspnet-version-x-aspnetmvc-version-and-x-powered-by-from-the-response-header-in-iis7.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-10-22 16:59:52
. Net Core
Aby usunąć nagłówek serwera W ramach programu .plik cs, dodaj następującą opcję:
.UseKestrel(opt => opt.AddServerHeader = false)
Dla dot net core 1, Umieść opcję Dodaj wewnątrz .Usekestrel () call. Dla dot net Core 2, Dodaj wiersz po usestartup ().
Aby usunąć nagłówek X-Powered-By, jeśli został wdrożony do IIS, edytuj swoją stronę.config i dodaj następującą sekcję wewnątrz systemu.webServer tag:
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
. NET 4.5.2
Aby usunąć nagłówek serwera z twojego globalnego.asax file add the following:
protected void Application_BeginRequest(object sender, EventArgs e)
{
string[] headers = { "Server", "X-AspNet-Version" };
if (!Response.HeadersWritten)
{
Response.AddOnSendingHeaders((c) =>
{
if (c != null && c.Response != null && c.Response.Headers != null)
{
foreach (string header in headers)
{
if (c.Response.Headers[header] != null)
{
c.Response.Headers.Remove(header);
}
}
}
});
}
}
Pre. NET 4.5.2
Dodaj następującą klasę c# do swojego projektu:
public class RemoveServerHeaderModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreSendRequestHeaders += OnPreSendRequestHeaders;
}
public void Dispose() { }
void OnPreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("Server");
}
}
A następnie w sieci.config dodaj następującą sekcję :
<system.webServer>
....
<modules>
<add name="RemoveServerHeaderModule" type="MyNamespace.RemoveServerHeaderModule" />
</modules>
Jednak miaĹ 'em problem, w ktĂłrym podprojekty nie mogĹ' y znaleĹşÄ ‡ tego MODUĹ ' u. To nie jest zabawne.
Usuwanie nagłówka X-AspNetMvc-Version
Aby usunąć Znacznik "X-AspNetMvc-Version", dla dowolnej wersji. NET, zmodyfikuj swoją " web.config " plik do włączenia:
<system.web>
...
<httpRuntime enableVersionHeader="false" />
...
</system.web>
Dzięki Microsoftowi za niewyobrażalne utrudnienie. A może taki był twój zamiar, abyś mógł śledzić instalacje IIS i MVC na całym świecie ...
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-03-12 23:50:35
W Asp.Net Core możesz edytować www.pliki konfiguracyjne jak TAK:
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
Możesz usunąć nagłówek serwera w opcjach:
.UseKestrel(c =>
{
// removes the server header
c.AddServerHeader = false;
})
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-09-29 22:25:41
Jak pokazano na stronie usuwanie standardowych nagłówków serwera na stronie Windows Azure Web Sites , można usunąć nagłówki za pomocą:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
</customHeaders>
</httpProtocol>
<security>
<requestFiltering removeServerHeader="true"/>
</security>
</system.webServer>
<system.web>
<httpRuntime enableVersionHeader="false" />
</system.web>
</configuration>
Usuwa nagłówek serwera i nagłówki X.
To działało lokalnie w moich testach w Visual Studio 2015.Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-11-19 21:26:50
Ze względu na kompletność, istnieje inny sposób na usunięcie nagłówka Server
, używając regedit.
Utwórz wpis DWORD o nazwie DisableServerHeader w następującym kluczu rejestru i ustaw wartość na 1.
HKLM \ SYSTEM\CurrentControlSet\Services \ http \ Parameters
Wolałbym znaleźć odpowiednie rozwiązanie za pomocą sieci.config, ale użycie <rewrite>
nie jest dobre, ponieważ wymaga zainstalowania modułu rewrite i nawet wtedy nie usunie nagłówka, po prostu go opróżnij.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-10-13 23:07:31
Możesz zmienić dowolny nagłówek lub cokolwiek w Application_EndRequest()
Spróbuj tego
protected void Application_EndRequest()
{
// removing excessive headers. They don't need to see this.
Response.Headers.Remove("header_name");
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-07-01 11:12:30
Nagłówek X-Powered-By jest dodawany przez IIS do odpowiedzi HTTP, więc można go usunąć nawet na poziomie serwera za pomocą Menedżera IIS:
Możesz korzystać z sieci.Config bezpośrednio:
<system.webServer>
<httpProtocol>
<customHeaders>
<remove name="X-Powered-By" />
</customHeaders>
</httpProtocol>
</system.webServer>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-03 07:52:54
Sprawdź Ten blog Nie używaj kodu do usuwania nagłówków. Jest niestabilny według Microsoft
Moje zdanie na ten temat:
<system.webServer>
<httpProtocol>
<!-- Security Hardening of HTTP response headers -->
<customHeaders>
<!--Sending the new X-Content-Type-Options response header with the value 'nosniff' will prevent
Internet Explorer from MIME-sniffing a response away from the declared content-type. -->
<add name="X-Content-Type-Options" value="nosniff" />
<!-- X-Frame-Options tells the browser whether you want to allow your site to be framed or not.
By preventing a browser from framing your site you can defend against attacks like clickjacking.
Recommended value "x-frame-options: SAMEORIGIN" -->
<add name="X-Frame-Options" value="SAMEORIGIN" />
<!-- Setting X-Permitted-Cross-Domain-Policies header to “master-only” will instruct Flash and PDF files that
they should only read the master crossdomain.xml file from the root of the website.
https://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html -->
<add name="X-Permitted-Cross-Domain-Policies" value="master-only" />
<!-- X-XSS-Protection sets the configuration for the cross-site scripting filter built into most browsers.
Recommended value "X-XSS-Protection: 1; mode=block". -->
<add name="X-Xss-Protection" value="1; mode=block" />
<!-- Referrer-Policy allows a site to control how much information the browser includes with navigations away from a document and should be set by all sites.
If you have sensitive information in your URLs, you don't want to forward to other domains
https://scotthelme.co.uk/a-new-security-header-referrer-policy/ -->
<add name="Referrer-Policy" value="no-referrer-when-downgrade" />
<!-- Remove x-powered-by in the response header, required by OWASP A5:2017 - Do not disclose web server configuration -->
<remove name="X-Powered-By" />
<!-- Ensure the cache-control is public, some browser won't set expiration without that -->
<add name="Cache-Control" value="public" />
</customHeaders>
</httpProtocol>
<!-- Prerequisite for the <rewrite> section
Install the URL Rewrite Module on the Web Server https://www.iis.net/downloads/microsoft/url-rewrite -->
<rewrite>
<!-- Remove Server response headers (OWASP Security Measure) -->
<outboundRules rewriteBeforeCache="true">
<rule name="Remove Server header">
<match serverVariable="RESPONSE_Server" pattern=".+" />
<!-- Use custom value for the Server info -->
<action type="Rewrite" value="Your Custom Value Here." />
</rule>
</outboundRules>
</rewrite>
</system.webServer>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-08-01 18:19:39