C# 默认HTTP头IIS 7';MvcHandler';在当前上下文中不存在

C# 默认HTTP头IIS 7';MvcHandler';在当前上下文中不存在,c#,asp.net-mvc,iis-7,web-config,global-asax,C#,Asp.net Mvc,Iis 7,Web Config,Global Asax,这是我在Global.asax中的代码 <%@ Application Language="C#" %> <script runat="server"> protected void Application_PreSendRequestHeaders() { Response.Headers.Remove("Server"); Response.Headers.Remove("X-AspNet-Version");

这是我在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>
但是我收到了这个错误: 当前上下文中不存在名称“MvcHandler”

在我的Web配置中,我使用以下代码

<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>

如何删除MVC默认HTTP头?
我无法删除HTTP头,我在这一行收到一个错误名称“MvcHandler”在当前上下文中不存在

可能重复@Fran我更新了代码,我在mvc中是如此的新,需要添加框架或?@Fran It's not duplicate这是我的错误名称“MvcHandler”在当前上下文中不存在在System.Web.Mvc中。如果要在asax而不是.cs文件中编写处理程序,则需要在.asax文件中包含System.Web.Mvc。你为什么不为Global.asax准备一个代码?这些是在创建项目时创建的。
<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>