2

Incorrect urls like http://localhost:54321/foo/bar and errors like HttpNotFound() are handled in my localhost without problems. After deploying to IIS 7.5, it return a blank page on both of the above scenarios. I've seen someone else had this problem Here(It was the comment from Moulde with several upvotes). The code:

Web.Config

<system.web>
  <customErrors mode="Off" redirectMode="ResponseRedirect">
    <error statusCode="404" redirect="~/Error/NotFound"/>
  </customErrors>
</system.web>
<httpErrors errorMode="Custom" existingResponse="Replace">
  <remove statusCode="404" />
  <error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound"/>
  <remove statusCode="500" />
  <error statusCode="500" responseMode="ExecuteURL" path="/Error/Error"/>
</httpErrors>

ErrorController

public class ErrorController : Controller
{
    public ActionResult NotFound() {
        Response.StatusCode = 404;
        Response.TrySkipIisCustomErrors = true;
        return View();
    }
}

RouteConfig

 routes.MapRoute(
            "Error - 404",
            "NotFound",
            new { controller = "Error", action = "NotFound" }
            );

        routes.MapRoute(
            "Error - 500",
            "Error",
            new { controller = "Error", action = "Error" }
            );
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

NotFound

<h2>404 Not Found</h2>
<div class="alert alert-info">
    <p><strong>Whoops...</strong></p>
    <p>The resource you were looking for doesn't exist</p>
</div>

The server runs Windows Server 2008 R2. When I go to .../foo/bar or an action returns HttpNotFound(), it returns a blank page. Any idea?

Home/Test

public class HomeController: Controller{
    // ...
    public ActionResult Test(){
        return HttpNotFound();
    }
}

Update: When I go to /Error/NotFound on server, it returns a blank page as well with 404. The response with Fiddler:

HTTP/1.1 404 Not Found
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5 
X-AspNetMvc-Version: 5.2
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?  QzpccWhlXFByb2plY3RzXFZlbmRvclBvcnRhbFxWZW5kb3JQb3J0YWxcRXJyb3JcTm90Rm91bmQ=?=
X-Powered-By: ASP.NET
Date: Thu, 23 Apr 2015 13:24:49 GMT
Content-Length: 5434

Update 2: If I take existingResponse="Replace" away, I can open Error/NotFound on the server. But still got blank page on MyServer/MyProject/foo/bar

Community
  • 1
  • 1
Quentin
  • 1,310
  • 18
  • 30
  • What happens when you visit /Error/NotFound ? Please check with Fiddler - and post the raw response here. – Pavel Chuchuva Apr 23 '15 at 04:13
  • @PavelChuchuva It returns a blank page as well. I've updated the question. – Quentin Apr 23 '15 at 13:44
  • You are getting closer. Please try deploying this test project http://dl.dropbox.com/u/2019363/Test404.zip Does it work on IIS? – Pavel Chuchuva Apr 24 '15 at 00:48
  • @PavelChuchuva It works on my localhost. After deployed to a different server with IIS 7.5 and .net 4.5, I can open /Home but /Home/About and Error/NotFound returns a 403 forbidden. I also deployed my project to this server, Error/NotFound works. but Home/Test (see code) returns 403 forbidden as well. – Quentin Apr 27 '15 at 19:24

1 Answers1

0

In my case the reason was in IIS - web settings - Request Filtering - SQL injection filter...

If url or query string contains ;, response ends with status 404.19 - Denied by filtering rule. Then blank page is displayed. IIS redirect to custom error like this http://server.com/Error404.aspx?404;http://server.com/missingURL and the char ; is why Request Filter end your request because of SQL injection.

Robert
  • 5,278
  • 43
  • 65
  • 115
Gogosz
  • 1
  • 1