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 it to serve the index.htm page and not use the MVC. how do I set that up? In IIS, I have index.htm as my start document and my global.asax has the standard "default" routing, where it calls the Home/Index.
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 = "" } // Parameter defaults
);
}
I added this:
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Context.Request.FilePath == "/") Context.RewritePath("index.htm");
}
it works. But is this the best solution?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With