4
votes

I have VS2010, MVC3 and ASP.NET 4.0 with a simple test mvc application. The problem is that I am still keep getting error:

Server Error in '/' Application.

The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Pizzas/Pizza

Here is my simple controller :

public class PizzasController : Controller
{
public ActionResult Pizza()
{
var pizzas = new Pizza();
return View("Pizza", pizza);
}

}

Here is a part of my global.asax:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("{Scripts}/{*pathInfo}");

        routes.MapRoute(
          "Pizza_1",
          "Pizzas/Pizza",
          new { controller = "Pizzas", action = "Pizza"}

      );

        routes.MapRoute(
            "Pizzas_2", // Route name
            "{controller}/{action}", // URL with parameters
            new { controller = "Pizzas", action = "Pizza" } // Parameter defaults
        );

        }

I am trying to call this action from a pizza.cshtml by this way:

@Html.ActionLink("Test", "Pizza", "Pizzas");

When the both routes are uncomented, then execution goes to Pizza_2 route and it passes without problems. But if I commented out Pizza_2, then it goes to Pizza_1 and the error occurs without getting to the action method. The application runs on ASP.NET development server (not IIS). I noticed that it works with Pizza_2 route only when there is no full url specified: http://localhost:2893

but if type the full url like this: http://localhost:2893/Pizzas/Pizza

the error again occurs.

2
And what happens when you comment Pizzas_1 and ucomment Pizzas_2, and then open localhost:2893/Pizzas/Pizza ? Verify first that this works without custom routes.Goran Obradovic
When only Pizza_2 is available, it works but not with the custom routes. Html.ActionLink works, but if use the full custom route then it failsttm

2 Answers

5
votes

Remove

    routes.IgnoreRoute("{Scripts}/{*pathInfo}");

According to http://msdn.microsoft.com/en-us/library/cc668201.aspx#url_patterns {Scripts} is parsed as parameter.

If you want to do passthrough for scripts, you should use

    routes.IgnoreRoute("Scripts/{*pathInfo}");
0
votes

I had the same issue but when i was looking at the warning list of the project i found out that i had a reference to the OracleDataAcces.dll. When rebuilding the project that dll was not able to be deleted due to the security problem. Then i right clicked the bin folder it was given only read only access then i deselected that and rebuilt again.

After that the page loaded without any issue. Hope this may resolve it.