开发者

MVC3, ASP.NET 4 - The resource cannot be found.

I have VS2010, MVC3 and ASP.NET 4.0 with a simple test mvc application. The pro开发者_开发知识库blem 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.


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}");


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜