If you don't ask for a particular page (http://localhost/) then your web server will assume default.aspx (some web servers let you customise this)
In the sample project default.aspx exists and so it is invoked. In the code behind (default.aspx.cs) you will see that it does a Response.Redirect to ~/Home
This new url (http://localhost/Home) does not match your first root but it does match the second root. The first part of the root (Home) provides the controller name (Mvc adds 'Controller' to the end of the name of the
controller, so the class that is invoked is actually HomeController). The "action" and "id" are not provided by your root and so you get the defaults which are "Login" and "" respectively as specified by the root definition.
The net result is that Mvc will attempt to invoke the Login method of the class HomeController. It looks like your HomeController class does not have a method with an appropriate signature called Login. You say that you have a routing problem but don't
specify exactly what your problem is. Did you not expect HomeController/Login to be invoked or is the problem that you have provided HomeController/Logion and it is not being invoked? If it is the former hopefully you can now see why Mvc is doing what it
is doing. If it is the latter can you post your HomeController code?
Also, in the routing configuration you've shown, you've got .mvc in your "parameter defaults", which won't work because your class names don't really have .mvc in them. If you want to use .mvc as a url "filename extension", put that in the URL patterm (e.g.
{controller}.mvc/{action}/{id}), but *not* in the parameter defaults.
Presumably you didn't actually have .mvc in the config when you ran it, otherwise you wouldn't have got the error message you described.
mhinton
Member
1 Points
1 Post
Preview 4 Routing Problem
Jul 23, 2008 02:42 AM|LINK
I am working on an asp.net mvc project locally on my XP machine and I am having a routing problem.
This url (http://localhost/) tries to load http://localhost/Home with the following routes setup.
routes.MapRoute( "Home", "default.aspx", new { controller = "Account.mvc", action = "Login" } ); routes.MapRoute( "Default", // Route name "{controller}.mvc/{action}/{id}", // URL with parameters new { controller = "Account.mvc", action = "Login", id = "" } // Parameter defaults );Paul Linton
Star
13421 Points
2535 Posts
Re: Preview 4 Routing Problem
Jul 23, 2008 03:35 AM|LINK
If you don't ask for a particular page (http://localhost/) then your web server will assume default.aspx (some web servers let you customise this)
In the sample project default.aspx exists and so it is invoked. In the code behind (default.aspx.cs) you will see that it does a Response.Redirect to ~/Home
This new url (http://localhost/Home) does not match your first root but it does match the second root. The first part of the root (Home) provides the controller name (Mvc adds 'Controller' to the end of the name of the controller, so the class that is invoked is actually HomeController). The "action" and "id" are not provided by your root and so you get the defaults which are "Login" and "" respectively as specified by the root definition.
The net result is that Mvc will attempt to invoke the Login method of the class HomeController. It looks like your HomeController class does not have a method with an appropriate signature called Login. You say that you have a routing problem but don't specify exactly what your problem is. Did you not expect HomeController/Login to be invoked or is the problem that you have provided HomeController/Logion and it is not being invoked? If it is the former hopefully you can now see why Mvc is doing what it is doing. If it is the latter can you post your HomeController code?
Good luck
SteveSanders...
Member
432 Points
119 Posts
Microsoft
Re: Preview 4 Routing Problem
Jul 23, 2008 10:44 AM|LINK
Also, in the routing configuration you've shown, you've got .mvc in your "parameter defaults", which won't work because your class names don't really have .mvc in them. If you want to use .mvc as a url "filename extension", put that in the URL patterm (e.g. {controller}.mvc/{action}/{id}), but *not* in the parameter defaults.
Presumably you didn't actually have .mvc in the config when you ran it, otherwise you wouldn't have got the error message you described.
http://blog.codeville.net/