[RESOLVED]Return 401 HTTP error status code

Recently I’ve updated my website from AJAX to ASP.MVC5, so the old urls which are still in the search engine need to be removed.

Because my old URLs is AJAX based, Google will not gonna remove them it self since every old urls will re-direct to the homepage , for example :


Now the solution is return to Google an 401 HTTP error status everytime the server receive a request from the old URL (contains #! or _escaped_fragment_)

How do I return this 401 HTTP error status code back to the "requester" proactively and globally in MVC5 ?



I’m happy to inform you that I’ve successfully implemented the feature and it’s working fine on my local host. Now I can even handle 404 error to custom page also.

But for some reasons, it’s not working after publishing to the host :( I still have ordinary 404 error code


for some reasons, it’s not working after publishing to the host :( I still have ordinary 404 error code

Talk with the host


To custom error message, you can archive that via IIS Manager or configure the two section in web.config manually.

    <customErrors defaultRedirect=”http://mysite.com/errors/Error.aspx” mode=”RemoteOnly”>
       <error redirect=”http://mysite.com/errors/404.aspx” statusCode=”404″ />



        <remove statusCode="401" subStatusCode="-1" />

        <remove statusCode="403" subStatusCode="-1" />     

        <remove statusCode="404" subStatusCode="-1" />               

        <remove statusCode="500" subStatusCode="-1" />

          <!– full url when responsemode is Redirect –>

        <error statusCode="401" path="http://foo.com/default.htm" responseMode="Redirect" />

          <!– local relative path when responsemode is ExecuteURL –>

        <error statusCode="403" path="/errors/403.htm" responseMode="ExecuteURL" />

        <error statusCode="404" path="/somedir/oops404.htm" responseMode="ExecuteURL" />               

        <error statusCode="500" path="/somedir/500.asp" responseMode="ExecuteURL" />


      <modules runAllManagedModulesForAllRequests="true"/>


Leave a Reply