title: web.config not forwarding to 404 error page on non .aspx pages
body: <h2>Objective</h2>
  
  <p>I want all URLs of missing pages to forward to my 404 page which is in my root as <code>404error.aspx</code></p>
  
  <h2>Problem</h2>
  
  <p>So far only the URLs that have a <code>.aspx</code> will work. For example, if you enter <code>4error.aspx</code> you will be redirected to the error page.</p>
  
  <pre><code>/404error.aspx?aspxerrorpath=/4error.aspx
  </code></pre>
  
  <h2>Background</h2>
  
  <p>I am not a .NET developer, so I just took over this project which uses classic <code>.aspx</code>. So I am not using any Microsoft product to build any of this in templates or frameworks. I am just coding in Sublime text.</p>
  
  <h3>What I already researched</h3>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/11045733/404-redirecting-for-non-aspx-pages">404 Redirecting for non aspx pages</a> - the answers there were incomplete or do not work.</li>
  <li><a href="https://stackoverflow.com/questions/11187609/404-does-not-append-aspxerrorpath-for-non-aspx-pages">404 does not append aspxerrorpath for non aspx pages</a>  - but that was a bit different than what I want.</li>
  </ul>
  
  <p>I view many articles that I found on Google but nothing had a full example that actually worked.</p>
  
  <h2>Code</h2>
  
  <p>This is the entire code that I started with in my <code>web.config</code></p>
  
  <h3>web.config</h3>
  
  <pre><code>&lt;configuration&gt;
    &lt;system.web&gt;
      &lt;customErrors mode="RemoteOnly" defaultRedirect="~/404error.aspx" /&gt;
        &lt;globalization
          fileEncoding="utf-8"
          requestEncoding="utf-8"
          responseEncoding="utf-8"
          culture="en-US"
          uiCulture="de-DE"
        /&gt;
    &lt;/system.web&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I have also found this example from Microsoft (404error.aspx was my modification)<br>
  <a href="http://msdn.microsoft.com/en-us/library/vstudio/bb397417%28v=vs.100%29.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/vstudio/bb397417%28v=vs.100%29.aspx</a></p>
  
  <h3>web.config (2)</h3>
  
  <pre><code>&lt;configuration&gt;
    &lt;appSettings/&gt;
    &lt;connectionStrings/&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" /&gt;
  
      &lt;!-- Turn on Custom Errors --&gt;
      &lt;customErrors mode="On" 
        defaultRedirect="/404error.aspx"&gt;
        &lt;error statusCode="404" redirect="/404Error.aspx"/&gt;
      &lt;/customErrors&gt;
  
    &lt;/system.web&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>That also did not handle pages that did not have the <code>.aspx</code></p>
  
  <p>Then I tried this example from </p>
  
  <h3>web.config (3)</h3>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
     &lt;system.web&gt;
      &lt;customErrors mode="RemoteOnly" defaultRedirect="~/404error.aspx" /&gt;
      &lt;error statusCode="404" redirect="~/404error.aspx" /&gt;
      &lt;globalization
        fileEncoding="utf-8"
        requestEncoding="utf-8"
        responseEncoding="utf-8"
        culture="en-US"
        uiCulture="de-DE"
      /&gt;
     &lt;/system.web&gt;
     &lt;system.webServer&gt;
        &lt;httpErrors&gt;
          &lt;remove statusCode="401" subStatusCode="-1" /&gt;
          &lt;remove statusCode="403" subStatusCode="-1" /&gt;      
          &lt;remove statusCode="404" subStatusCode="-1" /&gt;                
          &lt;remove statusCode="500" subStatusCode="-1" /&gt;
            &lt;!-- full url when responsemode is Redirect --&gt;
          &lt;error statusCode="401" path="http://foo.com/default.htm" responseMode="Redirect" /&gt;
            &lt;!-- local relative path when responsemode is ExecuteURL --&gt;
          &lt;error statusCode="403" path="~/404error.aspx" responseMode="ExecuteURL" /&gt;
          &lt;error statusCode="404" path="~/404error.aspx" responseMode="ExecuteURL" /&gt;                
          &lt;error statusCode="500" path="~/404error.aspx" responseMode="ExecuteURL" /&gt;
        &lt;/httpErrors&gt;
        &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
     &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Obviously I have to change the paths for other-than-404 pages but I just wanted to test it for those errors. That last <code>web.config</code> works even worse. </p>
  
  <p>Can you please tell me what I need to modify. I would appreciate a full <code>&lt;configuration&gt;</code> because I keep getting confused what goes where.</p>
  
  <h2>EDIT 1</h2>
  
  <p>I had read that many developers were suggesting to just make it a HTML page. So now my page is <code>404.html</code> Here is my updated <code>web.config</code></p>
  
  <pre><code>&lt;configuration&gt;
    &lt;system.web&gt;
      &lt;customErrors mode="On"
                redirectMode="ResponseRewrite"&gt;
          &lt;error statusCode="404"
             redirect="~/404.html"/&gt;
        &lt;/customErrors&gt;
        &lt;globalization
          fileEncoding="utf-8"
          requestEncoding="utf-8"
          responseEncoding="utf-8"
          culture="en-US"
          uiCulture="de-DE"
        /&gt;
    &lt;/system.web&gt;
  
    &lt;system.webServer&gt;
      &lt;httpErrors errorMode="Custom"
              defaultResponseMode="File"&gt;
        &lt;remove statusCode="404"/&gt;
        &lt;error statusCode="404"
            path="~/404.html"/&gt;
      &lt;/httpErrors&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>