Set the ASP. NET MVC site default page to an. html page.

Source: Internet
Author: User

A colleague deploys an ASP. NET MVC site, wants its default page to be index.html page, adds index.html to the site root in vs2010, and then calls no problem, but deploys to IIS7, in function attempt = " The default document added Index.html, but only the domain name or not access, it seems that the reasons for. NET MVC and IIS incompatibility, and later colleagues adopted the method is to write the default page in the global file to log in a page, so because there is no permissions, The system will automatically jump to the login page

public static void RegisterRoutes (RouteCollection routes)
{
Routes. Ignoreroute ("{resource}.axd/{*pathinfo}");

Routes. MapRoute (
"Default",//route name
' {controller}/{action}/{id} ',//URL with parameter
New {controller = "indexpage", action = "Index", id = urlparameter.optional}//parameter default value
);
}

Friends found a good blog, feel more flexible implementation methods, as follows:

Method 1:

In the Global.asax file, add

protected void Application_BeginRequest (object sender, EventArgs e)
{
if (Context.Request.FilePath = = "/") Context.rewritepath ("index.html");
}

Method 2:

Create a new route Defaultcontroller, set it as the default route, and increase it in action

Redirect (Url.content ("~/index.html"));

This method needs to modify the Web. config configuration

Add in the <compilation> node in the Web. config file:

<buildProviders>
<add extension= ". htm" Type= "System.Web.Compilation.

Set the ASP. NET MVC site default page to an. html page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.