I am using IIS 6. I think my problem is that I don\'t know how to route to a non controller using the routes.MapRoute.
I have a url such as example.com and I want i
I added a dummy controller to use as the default controller when the root of the web site is specified. This controller has a single index action that does a redirect to the index.htm site at the root.
public class DocumentationController : Controller
{
public ActionResult Index()
{
return Redirect( Url.Content( "~/index.htm" ) );
}
}
Note that I'm using this a the documentation of an MVC-based REST web service. If you go to the root of the site, you get the documentation of the service instead of some default web service method.
routes.IgnoreRoute ?
Also, see this question: How to ignore route in asp.net forms url routing
Configure the asp.net routing to ignore root ("/") requests
and let IIS's "Default Document"
ISAPI filter serve the static index.htm
file
Add the following to the RegisterRoutes
method.
routes.IgnoreRoute("");
The best solution is to remove the default Controller. You're running into this issue, because you're specifying both the default page and the default route without any parameters.
By just removing the controller = "Home"
on the route defaults, the /
won't match the route anymore and because no other route will satisfy, IIS will look into the default documents.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { action = "Index", id = "" } // Parameter defaults
);
}