title: respond with status code 410 from asp.net mvc for legacy .asp page
body: <p>I'm using asp.net mvc 4.0. I need to respond with 410 status code for specific legacy page: oldpage.asp</p>
  
  <p>here is my web.config to handle error pages</p>
  
  <pre><code> &lt;system.web&gt;
  
      &lt;customErrors mode="RemoteOnly" redirectMode="ResponseRewrite" defaultRedirect="~/500.aspx"&gt;
        &lt;error statusCode="404" redirect="~/404.aspx"/&gt;
        &lt;error statusCode="500" redirect="~/500.aspx"/&gt;
      &lt;/customErrors&gt;
  
  
    &lt;/system.web&gt;
  
   &lt;system.webServer&gt;
  
      &lt;httpErrors errorMode="Custom"&gt;
        &lt;remove statusCode="404"/&gt;
        &lt;error statusCode="404" path="404.html" responseMode="File"/&gt;
        &lt;remove statusCode="500"/&gt;
        &lt;error statusCode="500" path="500.html" responseMode="File"/&gt;
      &lt;/httpErrors&gt;
  
  
    &lt;/system.webServer&gt;
  </code></pre>
  
  <p>Here is my code in global.asax. I want to distinguish between .asp and .aspx requests, but .asp requests never make it here and I always get 404 for it.</p>
  
  <pre><code>  void Application_BeginRequest(Object source, EventArgs e)
          {
  
              string reqURL = HttpContext.Current.Request.Url.AbsoluteUri.ToLower();
  
              if(reqURL.Contains("/oldpage.asp") &amp;&amp; !reqURL.Contains("/oldpage.aspx")){
                  Response.Status = "410 Gone";
                  Response.StatusCode = 410;
                  Response.Write(Response.Status);
                  Response.End();
              }
  }
  </code></pre>
  
  <p>The code in global.asax never gets executed if my request ends with .asp, it works for other requests. What should I change to handle this? </p>