2

I tried to catch 404 errors like this... But

  1. when i try to load http://localhost:11415/wfwe/wefwe/ - all good work.
  2. When i try to load http://localhost:11415/order/ - fail (with error The RouteData must contain an item named 'action' with a non-empty string value.)
  3. When i try to load http://localhost:11415/Images/ - fail with error File does not exist

My routes:

      routes.Add("Order", new LowercaseRoute("Order/{action}/{id}",
                                               new RouteValueDictionary(
                                                   new
                                                       {
                                                           controller = "Order",
                                                           action = "",
                                                           id = UrlParameter.Optional
                                                       }),
                                               new MvcRouteHandler()));
routes.Add("NotFound", new LowercaseRoute("{*url}", new RouteValueDictionary(
                                                 new
                                                 {
                                                     controller = "Pages",
                                                     action = "Http404",
                                                 }),
                                             new MvcRouteHandler()));

Why route NotFound - don't catch all 404 error. And When i try to upload to my hosting and try 404 i get this error (NotFound route not work at all) 404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

I work with this all day, but nothig... please help me

Community
  • 1
  • 1
Dmitriy
  • 552
  • 1
  • 6
  • 20

2 Answers2

2

When i try to load http://localhost:11415/order/ - fail (with error The RouteData must contain an item named 'action' with a non-empty string value.)

Because of this:

new { controller = "Order", action = "", id = UrlParameter.Optional }

You need to specify an action.

When i try to load http://localhost:11415/Images/ - fail with error File does not exist

If there is Images folder on your server, then it will "intercept" requests not letting them through to the MVC pipeline.

  • thanks a lot. And why on hosting i get standart httperrors 404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable, and not my 404 erorr? – Dmitriy Jun 08 '10 at 14:21
  • @Dmitriy: Because "your 404" would be provided by some custom view which will only be served back if MVC is handling the request. In case with files it isn't. You could specify a static page in your web.config to be returned in that case. –  Jun 08 '10 at 14:25
  • Oh, no. on localhost with url: http://localhost:11415/wfwe/wefwe/ - all good fine, but on site - it's bad. my site: http://www.kidemon.ru/wqefwef/we - standart error, not my. – Dmitriy Jun 08 '10 at 14:28
  • 1
    @Dmitriy: Could have something to do with IIS configuration on the hosting. Also check that the web.config has the customErrors option set to "on". –  Jun 08 '10 at 14:39
2

I make this:

  routes.Add("NotFound", new LowercaseRoute("{*url}", new RouteValueDictionary(
                                                 new
                                                 {
                                                     controller = "Pages",
                                                     action = "Http404",
                                                 }),
                                             new MvcRouteHandler()));

and this in web.config

 <customErrors mode="On">
 </customErrors>

and

<modules runAllManagedModulesForAllRequests="true"/>
<handlers/>
<httpErrors>
  <remove statusCode="404"/>
  <error statusCode="404" path="/page/http404/" responseMode="ExecuteURL"/>
</httpErrors>

This works how i want.

Mehdi Haghshenas
  • 2,433
  • 1
  • 16
  • 35
Dmitriy
  • 552
  • 1
  • 6
  • 20