0

Here is my code in Global.asax

<%@ Application Language="C#" %>

<script runat="server">



    protected void Application_PreSendRequestHeaders()
    {
       Response.Headers.Remove("Server");
       Response.Headers.Remove("X-AspNet-Version");
       Response.Headers.Remove("X-AspNetMvc-Version");

    }


</script>

I use this code too

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

but I received this error : The name 'MvcHandler' does not exist in the current context

in my Web config I use this code

<configuration>

    <system.web>
    <httpRuntime enableVersionHeader="false" targetFramework="4.5" />
    <compilation debug="true" targetFramework="4.5"/>
    </system.web>
  <system.webServer>

     <httpProtocol>
      <customHeaders>
      <clear />
        <remove name="X-Powered-By" />
      </customHeaders>
   </httpProtocol>

    <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
      <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
      <dynamicTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/json" enabled="true" />
        <add mimeType="*/*" enabled="false" />
      </dynamicTypes>
      <staticTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/atom+xml" enabled="true" />
        <add mimeType="application/xaml+xml" enabled="true" />
        <add mimeType="*/*" enabled="false" />
      </staticTypes>
    </httpCompression>

    <urlCompression doStaticCompression="true" doDynamicCompression="true" />

        <rewrite>
            <rules>
                <clear />
                <rule name="Redirect to https" stopProcessing="true">
                    <match url=".*" />

                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>




 <modules runAllManagedModulesForAllRequests="true">     
   </modules>    
  </system.webServer>

</configuration>

How can I remove MVC Default HTTP Headers ? I can't remove the HTTP Header and I received one error in this line The name 'MvcHandler' does not exist in the current context

MidDev
  • 182
  • 1
  • 15
  • Possible duplicate of [How to remove ASP.Net MVC Default HTTP Headers?](https://stackoverflow.com/questions/3418557/how-to-remove-asp-net-mvc-default-http-headers) – Fran Jul 25 '18 at 23:47
  • @Fran I updated the codes and I am so new in mvc I need to add framework or ? – MidDev Jul 25 '18 at 23:53
  • @Fran its not duplicate here is my error The name 'MvcHandler' does not exist in the current context – MidDev Jul 26 '18 at 00:04
  • 1
    MvcHandler lives in System.Web.Mvc. You need to include System.Web.Mvc in your .asax file if you are going to write you handlers in the asax and not the .cs file. Why don't you have a codebehind for the Global.asax? Those are created when the project is created. – Fran Jul 26 '18 at 00:37

0 Answers0