MVC Framework - Routing

  • Thread starter Thread starter Chris Marsh
  • Start date Start date
C

Chris Marsh

All

I've just stated playing with the MVC framework included in the ASP .NET
Extensions release, but I'm hving trouble with the default settings.

I have created a default ASP .NET MVC Web Application, which includes a
default controller (HomeController) and two default views (Index and About).
The routes in Global.asax are as follows:

RouteTable.Routes.Add(new Route
{

Url = "[controller]/[action]/[id]",

Defaults = new { action = "Index", id = (string)null },

RouteHandler = typeof(MvcRouteHandler)

});

RouteTable.Routes.Add(new Route

{

Url = "Default.aspx",

Defaults = new { controller = "Home", action = "Index", id = (string)null },

RouteHandler = typeof(MvcRouteHandler)

});

However, only the second route appears to work. I would expect the first to
allow access to the Index page in a browser via the URL
http://localhost/Home/Index, but this gives an HTTP 404 error. I have
changed nothing in the default application, I have just built it and
attempted to access the pages in a browser. Can anyone give me any pointers
as to why this route does not appear to work?

Many thanks for any assistance!
 
All

I've just discovered that everything works fine when running the application
from Visual Studio; using F5 to launch the debugger.

Any pointers would be very much appreciated.
 
I have detailed the wiring of MVC on my blog.
http://gregorybeamer.spaces.live.com/blog/cns!B036196EAF9B34A8!459.entry

This is a very basic blog entry. Check Scott Guthrie's
(http://weblogs.asp.net/scottgu/) and Scott Hanselman's
(http://www.hanselman.com/blog/) blog for more detailed entries.

You should also check out Phil Haack's blog, especially if you are into TDD.
http://haacked.com/

Palermo has also written an article for Code magazine:
http://www.code-magazine.com/Article.aspx?quickid=070173

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
Chris Marsh said:
All

I've just discovered that everything works fine when running the
application from Visual Studio; using F5 to launch the debugger.

Any pointers would be very much appreciated.

--
Regards

Chris Marsh

Chris Marsh said:
All

I've just stated playing with the MVC framework included in the ASP .NET
Extensions release, but I'm hving trouble with the default settings.

I have created a default ASP .NET MVC Web Application, which includes a
default controller (HomeController) and two default views (Index and
About). The routes in Global.asax are as follows:

RouteTable.Routes.Add(new Route
{

Url = "[controller]/[action]/[id]",

Defaults = new { action = "Index", id = (string)null },

RouteHandler = typeof(MvcRouteHandler)

});

RouteTable.Routes.Add(new Route

{

Url = "Default.aspx",

Defaults = new { controller = "Home", action = "Index", id =
(string)null },

RouteHandler = typeof(MvcRouteHandler)

});

However, only the second route appears to work. I would expect the first
to allow access to the Index page in a browser via the URL
http://localhost/Home/Index, but this gives an HTTP 404 error. I have
changed nothing in the default application, I have just built it and
attempted to access the pages in a browser. Can anyone give me any
pointers as to why this route does not appear to work?

Many thanks for any assistance!
 
Gregory

Thanks very much for the informative links. It transpired that my problem
stemmed from my use if IIS6. Although I followed instructions and used a
..mvc suffix, I had not registered this suffix with IIS for hand-off to the
ASP .NET ISAPI filter.

I've learnt a lot along the way though, so despite the frustration over
something small it's been a worthwhile experience :)

Cheers!

--
Regards

Chris Marsh

Cowboy (Gregory A. Beamer) said:
I have detailed the wiring of MVC on my blog.
http://gregorybeamer.spaces.live.com/blog/cns!B036196EAF9B34A8!459.entry

This is a very basic blog entry. Check Scott Guthrie's
(http://weblogs.asp.net/scottgu/) and Scott Hanselman's
(http://www.hanselman.com/blog/) blog for more detailed entries.

You should also check out Phil Haack's blog, especially if you are into
TDD.
http://haacked.com/

Palermo has also written an article for Code magazine:
http://www.code-magazine.com/Article.aspx?quickid=070173

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box! |
*************************************************
Chris Marsh said:
All

I've just discovered that everything works fine when running the
application from Visual Studio; using F5 to launch the debugger.

Any pointers would be very much appreciated.

--
Regards

Chris Marsh

Chris Marsh said:
All

I've just stated playing with the MVC framework included in the ASP .NET
Extensions release, but I'm hving trouble with the default settings.

I have created a default ASP .NET MVC Web Application, which includes a
default controller (HomeController) and two default views (Index and
About). The routes in Global.asax are as follows:

RouteTable.Routes.Add(new Route
{

Url = "[controller]/[action]/[id]",

Defaults = new { action = "Index", id = (string)null },

RouteHandler = typeof(MvcRouteHandler)

});

RouteTable.Routes.Add(new Route

{

Url = "Default.aspx",

Defaults = new { controller = "Home", action = "Index", id =
(string)null },

RouteHandler = typeof(MvcRouteHandler)

});

However, only the second route appears to work. I would expect the first
to allow access to the Index page in a browser via the URL
http://localhost/Home/Index, but this gives an HTTP 404 error. I have
changed nothing in the default application, I have just built it and
attempted to access the pages in a browser. Can anyone give me any
pointers as to why this route does not appear to work?

Many thanks for any assistance!
 
Back
Top