Reputation: 2374
I have an ASP.NET Core 2.0 MVC app using Razor pages stored in the project tree under the /Pages folder.
The project is set up using default routing etc.
I would like to all the Razor pages to have .html extension in the browser's address bar.
File /Pages/test.cshtml is currently available via http://localhost/test. I would like this page to be available via http://localhost/test.html instead.
I tried to understand the routing settings but failed to understand it enough to come with the solution.
What should I write where so the files are available via .html suffix?
Upvotes: 5
Views: 1310
Reputation: 3113
defined a route for this as follows
routes.MapRoute(
"MyHtml",
"{controller}/{action}.html",
new { controller = "Home", action = "Index" });
and add HtmlFileHandler
to web.config. And .html
routes work now.
<handlers>
<add name="HtmlFileHandler" path="*.html" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
Upvotes: 3