ASP.NET MVC controller call when requesting .html file

I need to add new life to an outdated application :)

I would like to call the MVC controller when a “static” HTML page is requested to add some markup to the page before returning it to the client.

I tried to follow the approach found in this thread: How to read web.config settings on a .html page?

... but although I defined this route:

routes.MapRoute(
    name: "Topic", 
    url: "html/{fileName}.html", 
    defaults: new { controller = "Topic", action = "Index" });

the controller is not called. I have my web.config with:

<remove name="WebServiceHandlerFactory-Integrated" />
<add name="HTML" path="*.html" verb="*" 
    type="System.Web.UI.PageHandlerFactory" 
    resourceType="File" preCondition="integratedMode" />

I suspect that I need to call something else besides the PageHandlerFactory file, or maybe the problem is something else.

UPDATE: My dev environment works with native pipeline mode, but I need to check if my production environment supports it.

+5
2

:

routes.RouteExistingFiles = true;

, - . HTML- HostingEnvironment.VirtualPathProvider GetFile - - MVC, , , .

, , , , MVC. , .

+6

, , , . , :

web.config html:

<system.web>
    <compilation>
      <buildProviders>
        <add extension=".html"
             type="System.Web.Compilation.PageBuildProvider" />
      </buildProviders>
    </compilation>
</system.web>

, .

MapRoute , . , Topic ActionResult Index().

, url - localhost.com:{port}/html/test.html /html/ , .

- MapRoute, aspx aspx , . , IIS MVC. aspx, , aspx, - MVC.

, IIS Express, Cassini. Cassini , IIS Express . , , " Visual Studio Development Studio...". , IIS Express.

+3

All Articles