2

My 404 redirection to the NotFound (Controller Action) is not working while deployed in Azure Websites. I am getting normal browser 404 instead of my custom 404 page. But they work locally when debugging in localhost in Visual Studio. This is my Web.Config.

<system.web>
    <!-- ........ -->
    <customErrors mode="RemoteOnly" defaultRedirect="~/Error/Index">
        <error redirect="~/Error/NotFound" statusCode="404" />
    </customErrors>
</system.web>

My ErrorController:

public class ErrorController : Controller
{
    public ViewResult Index()
    {
        ViewBag.Title = "Error Page";
        var model = new ErrorViewModel() {ErrorMessage = "Sorry for the error!", TitleBar = "Error Page"};
        return View("Error", model);
    }

    public ViewResult NotFound()
    {
        Response.StatusCode = 404; //you may want to set this to 200
        return View("PageNotFound");
    }
}

Will appreciate your help.

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
Andy T
  • 1,355
  • 2
  • 19
  • 30
  • 2
    possible duplicate of [Windows Azure Websites is overriding my 404 and 500 error pages in my node.js app](http://stackoverflow.com/questions/15144405/windows-azure-websites-is-overriding-my-404-and-500-error-pages-in-my-node-js-ap) – Simon W Feb 17 '15 at 03:03

1 Answers1

1

It seems like the issue is fixed by adding the following under in your web.config file:

<system.webServer>
    <httpErrors existingResponse="PassThrough" />
</system.webServer>

This is because PassThrough leaves the existing response, as long as there is one. So you can define the error page.

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
Khaled Zayed
  • 306
  • 2
  • 6