2

how can we point the default file to something like index.html instead of the default action Home/Index

1
  • I would like to use the static page as my landing page instead of a dynamic one Commented Apr 19, 2009 at 0:49

4 Answers 4

1

In IIS configure the default document to be index.html at the top of the list?

Or you could add an IgnoreRoute to your global.asax

public static void RegisterRoutes(RouteCollection routes)
{
   routes.RouteExistingFiles = true;
   routes.IgnoreRoute("{file}.html");
   ...
Sign up to request clarification or add additional context in comments.

1 Comment

i think this is the opposite of what he is asking. he wants to use the index.html as his homepage not ignore it.
1

I found that under IIS 6 at least the default document pickup was interfered with when you used a wildcard catchall to route most requests into the MVC.

My solution (just for the root path in my case) was as follows: (in global.asax)

if (Request.Path == "" || Request.Path == "/") { Response.Redirect(Request.Path + "index.htm",true); return; }

This picked up the request and redirected it to the correct location. Rewriting the path using Context.RewritePath(Request.Path + "index.htm"); instead of the redirect also seems to work. A further revision would probably be to see if the final character of the path is '/' and if so check whether the corresponding file (thatpath/index.htm) exists and redirecting if it does... this would effectively allow MVS to keep working while providing logic so any folders that do exist that have a default document like that will serve that.

Comments

0

You can change the default controller action by adding or changing a route in the Global.asax.cs file of your project.

In the template, the following is included:

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = null });

If you want to point to a different controller action by default, just change the values in the anonymous type on the fourth line of code above.

Comments

0

I added

        routes.IgnoreRoute("");

to my route configuration. This ignores the root folder and if you have an index.html file in your root, it will get picked up.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.