1

I'm serving a static HTML file in the wwwroot folder of the .NET 6 Web API

How can I remove or hide the .html extension? I tried implementing mod_rewrite rules in web.config file here but it did not work. I renamed the web.config file to app.config as recommended here but still did not work.

So basically, what I want to achieve is Uri rewrite from https://localhost:5000/documentation.html to https://localhost:5000/documentation

How is this done in Web API that is serving a static file?

Bloggrammer
  • 921
  • 8
  • 21
  • why do you have .html files in web api project? – Lei Yang Mar 18 '22 at 06:47
  • For the API documentation. I want to avoid having to host the static HTML file elsewhere when I can just use the `app.UseStaticFiles();` available in the web API project. See https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-6.0 – Bloggrammer Mar 18 '22 at 06:49
  • so i think you don't have to emphasize webapi. you're just asking about asp.net mvc. – Lei Yang Mar 18 '22 at 06:55
  • @Mate Thanks for sharing the link. I've tried out the answers but none work for me. I have tried the accepted answer before and it works but the only issue I have with it is that it requires me to add CSS and JavaScript inside the HTML file (internal or inline) and difficult to reference an image in the HTML `` tag. I would love to add the CSS externally using the `` element. – Bloggrammer Mar 18 '22 at 07:14
  • @Blogrammer , using inside html works for me. You need add your.css into wwwroot/css. You could check from browser http://yoursite/css/your.css too – Mate Mar 18 '22 at 08:05
  • @Mate, yes it works for me too. You know when I first tried the controller approach, I was using `File(..)` instead of `Content(...)` or `Text(..)` Many thanks, you save my day. – Bloggrammer Mar 18 '22 at 08:13
  • This answer: https://stackoverflow.com/a/48770473/12476466 solve my problem. Thanks to @Mate for sharing the link. – Bloggrammer Mar 18 '22 at 08:19

0 Answers0