0

Locally, using IIS Express, I can return a view and a 404 code from an MVC 5 action.

When deployed on IIS 7.x, the server seems to want to take control and send its own crappy HTML for the 404.

How can I tell IIS to keep its big nose out of my 404 business?

In fact, even with custom errors on, an action that returns HttpStatusCodeResult(404) and a redirect/rewrite to another action with a view, it still returns the IIS page.

Luke Puplett
  • 42,091
  • 47
  • 181
  • 266

1 Answers1

0

This worked:

        this.Response.StatusCode = 404;
        this.Response.TrySkipIisCustomErrors = true;

        return View();

Now I found the answer I also found duplicate questions and a better answer - see most-voted answer here:

IIS7 Overrides customErrors when setting Response.StatusCode?

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

It's really about time IIS was taken out the back and shot.

Community
  • 1
  • 1
Luke Puplett
  • 42,091
  • 47
  • 181
  • 266