Is it possible to remove information from Server Error pages in ASP.NET 4.0?

岁酱吖の 提交于 2019-12-06 02:14:56

To hide .NET version information from .NET error pages (not generic IIS errors like 403, 404 etc.), use empty element without defaultRedirect attribute:

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly"/>
    </system.web>
</configuration>

Before:

After:

To remove X-AspNet-Version HTTP response header, set the enableVersionHeader to False on httpRuntime element:

<configuration>
    <system.web>
        <httpRuntime enableVersionHeader="False"/>
    </system.web>
</configuration>

In IIS this problem can be resolve changing "HTTP Response Headers" configuration


To remove X-AspNet-Version, in the web.config find/create <system.web> and add:

  <system.web>
    <httpRuntime enableVersionHeader="false" />

    ...

To remove X-AspNetMvc-Version, go to Global.asax, find/create the Application_Start event and add a line as follows:

  protected void Application_Start()
  {
      MvcHandler.DisableMvcResponseHeader = true;
  }

To remove X-Powered-By, in the web.config find/create <system.webServer> and add:

  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <remove name="X-Powered-By" />
      </customHeaders>
    </httpProtocol>

    ...

The problem could be that IIS is rendering the error page instead of ASP.NET. Try changing the system.webServer section of your web.config like this:

<system.webServer>
  <httpErrors errorMode="Custom" existingResponse="Replace">
    <remove statusCode="500" subStatusCode="-1" />
    <error statusCode="500" subStatusCode="-1" responseMode="ExecuteURL" path="/500.aspx" />
  </httpErrors>
</system.webServer>

Also, check you IIS settings, that's probably where the X-AspNet-Version header is being set.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!