Can't return HTTP status 404 for custom error page in ASP.NET
<p>One of our legacy websites based on the classic ASP.NET technology was moved to a new hosting. Now it's a cloud running Windows Azure Pack in which our site is running under .NET Framework 4.6.1.</p>

<p>However, I still can't return a custom error page for a non-existing .aspx resource with the correct HTTP status 404 - the status is always 302. Originally the custom 404 error page was defined like this in web.config:</p>

<pre class="lang-xml prettyprint-override"><code>&lt;system.web&gt;
    &lt;customErrors mode="RemoteOnly" defaultRedirect="/error/server-error.aspx"&gt;
        &lt;error statusCode="404" redirect="/error/resource-not-found.aspx"/&gt;
    &lt;/customErrors&gt;
&lt;/system.web&gt;
</code></pre>

<p>I did read SO posts like <a href="https://stackoverflow.com/questions/4302566/asp-net-custom-error-page-for-404-returns-302-for-http-status">this</a> and tried the suggested answers including setting the redirectMode to ResponseRewrite, but nothing helped or did not work as expected.</p>

<p>Did I miss something, or is there another solution?</p>