felipekm
felipekm

Reputation: 2910

Opening Default document on IIS

I've a deployed ASP.NET Web API with a website on the same folder that consume it.

When I type the URL on the Browser such as http://domain.com/ it returns a 404, but if I type http://domain.com/index.html it works!

I wanna know if there's a way to configure it on Web API route, define a default route for it, redirecting to my http://domain.com/index.html when I type http://domain.com/

I've tried ti put this on Web.Config without success:

<defaultDocument enabled="true">
  <files>
    <add value="/index.html" />
  </files>
</defaultDocument>

Also, I set up my IIS to only accept index.html default document. no success =/

Any ideas?

Upvotes: 3

Views: 3871

Answers (2)

Tom Stickel
Tom Stickel

Reputation: 20411

Well, It is situational, for what you are doing that is fine.

I have done things like:

routes.IgnoreRoute("");

I typically still end up with problems when the default mvc portion of web api is hit and so for me I end up doing this

public ActionResult Index()
{
        string filePath = Server.MapPath("~/contact.html");

        if (System.IO.File.Exists(filePath))
        {
            return File(filePath, "text/html");
        }

        return View();
}

Upvotes: 2

felipekm
felipekm

Reputation: 2910

I'm not sure if this is the best way to achieve this, I just edited my RouteConfig.cs such this:

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

        routes.MapRoute(
            name: "Default",
            url: "index.html"
        );
    }
}

Now I can get http://domain.com works perfectly!

I'd love If anyone have a best way to achieve this!

Upvotes: 2

Related Questions