2

I have a simple ASP MVC project. Under this site I need to show plain .html files, without treating routes as controller/action.

I have folder documentation with file index.html in it. I need to have this accessible under www.mydomain.com/documentation, it returns 403. Currently it works only under www.mydomain.com/documentation/index.html

I have added

routes.Ignore("developers/");

into RouteConfig.cs

and in Startup.cs for OwinAppBuilder

        app.UseStaticFiles();

What should I do to have it accessible under www.mydomain.com/documentation/index.html ?

Maarty
  • 1,140
  • 1
  • 12
  • 27
  • are you able to serve other static files, like .js and .png? Also what version of IIS are you running? – Sam W Dec 22 '16 at 14:53
  • nor Core? For Core see: http://stackoverflow.com/a/41093539/240564 – Alexan Dec 22 '16 at 14:54
  • well I can actually show the file, the problem is that I need to explicitly write "index.html" into URL... when I disable all MVC, and have site running, everything works – Maarty Dec 22 '16 at 14:58

1 Answers1

1

In your route config add

routes.RouteExistingFiles = true;
routes.MapRoute(
    name: "staticFileRoute",
    url: "Public/{*file}",
    defaults: new { controller = "Home", action = "HandleStatic" }
);

In you web.config under <system.webServer>/<handlers> add

<add name="MyCustomUrlHandler2" path="Public/*" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

Taken from this site if you want to read more about it.

Edit: note that the url in the MapRoute has the directory Public in the url, as well as in the path for the web.config line. If your html file is not in a directory named Public you will need to change that part to match your directory structure.

Sam W
  • 599
  • 2
  • 16
  • well this handles routes like domain.com/documentation/index.html.. but I need the opposite, I need to transform urls like domain.com/documentation into domain.com/documentation/index.html, to show the html file – Maarty Dec 22 '16 at 15:09
  • Give this a look: [http://stackoverflow.com/a/4552992/6442320](http://stackoverflow.com/a/4552992/6442320) – Sam W Dec 22 '16 at 15:28