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.
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.
Related
I just created a new basic MVC 4 application in VS 2010. I just clicked the play button to test it came up in the web browser and I'm getting the following page:
I think I need to change my virtual path to something but I don't know what.
EDIT: Can't see what it says properly in the picture:
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: /
If you created an Empty Project you will need to create a HomeController with an Index Action. You will also need to create a View in ~/Views/Home/ called Index.
The other project templates create this for you but the Empty Project does not.
public class HomeController : Controller
{
public ActionResult Index()
{
return View()
}
}
No one person gave me the full answer. So this is an amalgamation of #MattiVirkkunen and #BrettAlfred
Add this within RouteConfig.cs
routes.MapRoute(
name: "Default",
url: "",
defaults: new { controller = "Home", action = "Home" }
);
Add this within HomeController.cs
public ActionResult Login()
{
return View();
}
Kya Neeta MVC me neyi ho Kya?? I am too :)
I think u have created a start-up page in your applicaition.
Type Http: //localhost:8080/Home/Index in your url
http: //localhost:/ControllerName/ActionName
if that does not work please create a new MVC application from scratch.
im not sure what i messed up, but i just keep getting the following error upon f5.
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: /
The following is my route, totally default and no changes.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
I have checked my project properties -> web tab, "Specific page" has nth. My project has Home folder with Index page.
Other pages are working only after manually inputting URL. For eg: http://localhost:21183/store/search
Thanks
Things to check:
You have a public class named HomeController that derives from Controller.
This HomeController class has a public Index action.
You have a corresponding view ~/Views/Home/Index.cshtml
You are testing this inside a web server which supports extensionless urls. For example this won't work out of the box in IIS 6.0.
Controller:
public class HomeController: Controller
{
public ActionResult Index()
{
return View();
}
}
Route I have defined is:
map.Route(new Route("Cars/{id}/Delete",
new RouteValueDictionary(new { controller = "Car", action = "Delete"}),
new MvcRouteHandler()));
In my view I've got:
Delete
Which when run tries to send a request to http://oursite/Car/122/Delete
My delete action in this Car controller looks like this:
public ActionResult Delete(int id)
{
//code is here
}
I noticed a couple things:
If I run this same code locally via my PC, the delete works flawlessly and is able to get to my action method. I'm running this over IIS 7 / Win 7
On our dev server, it's setup obviously via IIS7 but this route fails and says it can't find the route on our route table. But this is the SAME route table class I am using locally...so why would I get this:
No route in the route table matches the supplied values.
But why would that not work on a dev server? I see the setup identical in IIS for the most part as far as I can see when I compare my local setup to the server's.
I noticed that also whether localhost or server, if I try and put an [HttpDelete] attribute on my delete action, it doesn't find my action method and I get an error saying it can't find that method. So not sure why when I take that off, the delete works (localhost only)
Use a helper to generate your link:
#Html.ActionLink("Delete", "Delete", "Car");
The first parameter is your link text, the second is your Action method name, and the third is your Controller name.
See this MSDN Reference on ActionLink().
Could you please share code for the View. How do you build the 'a' tag in the view?
Regarding the [HttpDelete] attribute, it means that the method needs the HTTP 'DELETE' request. The 'a' tag always has a GET request.
Please refer this link
I think you answered your own question. There is no route in the route table that matches your supplied values. You could write that route to do that by writing this in your Global.asax.cs file:
public class Global : System.Web.HttpApplication
{
protected void Application_Start()
{
// Specify routes
RouteTable.Routes.Add(new Route
{
Url = "[controller]/[id]/[action]",
Default = new { controller = "Car" },
RouterHandler = typeof(MvcRouteHandler)
});
}
}
Or, you can use existing routes (my personal recommendation) to use the Delete function in your Car controller. To do that, try switching your code to this:
Delete
First name that route
map.Route("DeleteCar",new Route("Cars/{id}/Delete",
new RouteValueDictionary(new { controller = "Car", action = "Delete"}),
new MvcRouteHandler()));
Then
Delete
Unless that link goes to a warning screen, I strongly suggest that a delete should be a POST or even a DELETE(I think it can be set via ajax)
There's likely a difference in the URL paths between localhost and oursite. The path "/Car/#Model.Id/Delete" is hard-coded, not resolved and may not work in all environments. As suggested in other answers, use an MVC helper like #Html.ActionLink or #Url.RouteUrl to resolve the path for the local environment.
I have an MVC 3 App with a few Areas built into it, one of the areas is my Admin section of my site. Everything was working just fine. I wanted to try MvcContrib Portable Areas to make my app more modular, so I installed MvcContrib and after some trial and error I got a couple Portable areas up and running.
Then I decided to move my Admin area up into a portable area, so i created the new project and stubbed out my Admin portable area. I had to rename my local Admin Area so that it would not conflict. While moving some code up to the Admin PA I decided that I did not want the headache of moving all the Telerik and other things I had wired up to my Admin area. SO I moved things back down to the main project Area and deleted the Admin PA.
I rewired my Admin Area back in and went over everything involved in setting up an Area. Now for the life of me I cannot get any of my areas in my main project to load. I keep getting the "The resource cannot be found." error message.
I even went as far as removing the reference to MvcContrib and Portable Areas but still no luck. I am at the end of my rope as I do not know how to debug this. I have used a custom route handler as well as Glimpse but neither are very useful when the error is thrown.
Here is the route in my global.asax
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
null,
new string[] { "CoolProject.Web.Controllers" }
);
here is the route in my admin area registration file
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "CoolProject.Web.Areas.Admin.Contollers" }
);
here is my Global.asax
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new string[] { "CoolProject.Web.Controllers" }
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
InitializeContainer();
AppStart_Structuremap.Start();
SiteMapManager.SiteMaps.Register<XmlSiteMap>("AdminNavigation", sitemap => sitemap.LoadFrom("/Areas/Admin/AdminNavigation.sitemap"));
}
I have checked my setup against a similar working site and everything is the same with the exception of namespaces and classes.
I am developing on Win 7 IIS7.5
Using Glimpse Routes plugin I can see that the routes exist but the problem is that the route in my Global.axas file is taking over all the requests to the areas.
What do I need to do with my routes to allow for the core app and the areas to get along? The funny thing is I have another production app using areas that works just fine.
Update....
I created a new MVC 3 Project, Added a single area named Admin. Then I edited the AdminAreaRegistration.cs and Global.asax files to include the namespaces in the MapRoute statement, compiled it and it runs perfectly. I can access the area with no problem.
I then compared the Global.asax and AdminAreaRegistration.cs with the files in my broken project and they are Identical. This is not an issue with how I set up my routes, I think there is another problem that I am not seeing.
Are you calling
AreaRegistration.RegisterAllAreas();
on Application_Start in your Global.asax? What server are you using for development Cassini, IISExpress, IIS?
Edit after reviewing more detailed information.
In your Admin Area Registration File if you have this code
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "CoolProject.Web.Areas.Admin.Contollers" }
);
I think there is a typo in "CoolProject.Web.Areas.Admin.Contollers" and it should be "CoolProject.Web.Areas.Admin.Controllers"?
Make sure the namespace is correct in your Controller, as well. If you created the new Area by copying MVC components from another MVC application, for instance (as I did) it's easy to forget to change the namespace!
I want to define two areas in MVC 3 project
"manager and main areas",
manager have some controles like main areas "the controler's Name in both have similar"
but I have implemented different methods in each controler
when I try to run my project, get this 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: /main/home
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
When I implement the project without use "Areas". I never get error, but my project is not clean
I'm assuming in your Global.asax in Application_Start you have:
AreaRegistration.RegisterAllAreas();
as one of the first steps yes?
And in the Area/Main folder you have a MainAreaRegistration.cs which is something like the following:
public class MainAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Main";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Main_default",
"Main/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "MyCompany.Web.Areas.Main.Controllers" }
);
}
}
I've found it necessary to fuly qualify routes with their appropriate namespaces (the namespace the controllers live in) once I have multiple areas to avoid confusion also. Obviously the namespace above is just how I structure mine, though whatever namespace your Main area controllers are in, that's the one to put in the file above.
Hope this helps.
Cheers,
Terry
In Global.asax try to change route to:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new string[] { "YourNamespace.Controllers" } // ADD THIS
);