zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Opening Default document on IIS (HTML With WebAPI)

OnHTMLWebAPI with iis Default Document opening
2023-09-11 14:21:33 时间

 

Question:

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 typehttp://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?

 

 

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!