I've got glimpse.
it's highlighting an empty line on the routes tab
Match Area Url Data constraints DataTokens
True Root -- --
Locally it seems cassini doesn't properly emulate a virtual directory so changing from localhost
to localhost/site
doesn't seem to grant any additional testing insight.
- Local testing
- cassini (windows 7 (32 and 64 bit are available))
- doesn't seem to use or allow integrated
- deploy environments
- IIS7 Integrated
- Tried a http routing setting to push
/
to /site
however I ran into trailing slash issues (/site
would route to /site/site
, while /site/
would work as expected
- web.config
- tried a few ways of setting
runAllManagedModules=false
with various errors
- using
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
that was linked
- tried
I need /site
(/~
) requests to go to ~/Default.aspx
would love for a way to have /
go there as well.
How do I do it?
To enable Default.aspx
as the default url you just need to remove your route handling so that there's no catch-all route.
By default all MVC 3 projects have:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
This is a catch-all route that will match everything you pass in your url. If you remove this and no path is defined then it will use whatever you set up as your default page in your web.config
.
To map /site
to Default.aspx
you just need to add a special route:
routes.MapPageRoute("SitetoDefault", "site", "~/Default.aspx");
This will see the /site
and route it to your default page.
You'll have to be careful when adding any other routes to your routing table. All of them will have to have a controller defined or you'll have to add a routing constraint. Something like this:
//controller defined
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
//route constraint
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new {
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}, // Parameter defaults
new { controller = "^(products)|(account)|(home)$" }
);
Here is more detail on creating more complex routing: http://www.asp.net/mvc/tutorials/creating-a-custom-route-constraint-cs