Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set index.html as the default page

I have an empty ASP.NET application and I added an index.html file. I want to set the index.html as default page for the site.

I have tried to right click on the index.html and set as start page, and when I run it the url is: http://localhost:5134/index.html but what I really want is that when I type: http://localhost:5134, it should load the index.html page.

my route config:

public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
like image 813
vir Avatar asked Mar 26 '14 09:03

vir


People also ask

Is index html the default?

Default Homepage The index. html page is the most common name used for the default page shown on a website if no other page is specified when a visitor requests the site.

What is index html default html?

The default file name for a website's home page (INDEX. HTM is also used). Appropriately named, the home page serves as an index to the main pages on the site, each of which can link to any number of other pages and so on.


5 Answers

I added an instruction to my route config to ignore empty routes and that solved my problem.

routes.IgnoreRoute(""); 
like image 80
vir Avatar answered Oct 17 '22 21:10

vir


As @vir answered, add routes.IgnoreRoute(""); to RegisterRoutes(RouteCollection routes) which you should find in RouteConfig.cs by default.

Here's what the method could look like:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.IgnoreRoute("");

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}

The reason is that ASP.NET MVC takes over URL management and by default the routing is such that all extensionless URLs are controlled by the extensionless Url handler defined in web.config.

There's a detailed explanation here.

like image 41
Alex Sanséau Avatar answered Oct 17 '22 21:10

Alex Sanséau


Assuming the web app is running in IIS, the default page can be specified in a web.config file:

<system.webServer>
    <defaultDocument>
        <files>
            <clear />
            <add value="index.html" />
        </files>
    </defaultDocument>
</system.webServer>
like image 8
Boris Lipschitz Avatar answered Oct 17 '22 21:10

Boris Lipschitz


Create a new controller DefaultController. In index action, i wrote one line redirect:

return Redirect("~/index.html")

In RouteConfig.cs, change controller="Default" for the route.

 routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional }
        );
like image 6
vickey1611 Avatar answered Oct 17 '22 21:10

vickey1611


One solution is this one:

 //routes.MapRoute(
 //           name: "Default",
 //           url: "{controller}/{action}/{id}",
 //           defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
 //      );

I mean, comment or delete this code in your MVC project to avoid the default behavior when you make the initial request http://localhost:5134/.

The index.html must be in the root of your solution.

Hope this helps! It works for me.

like image 3
sergio Avatar answered Oct 17 '22 21:10

sergio