ASP.NET WebPages use html extension

前端 未结 2 1945
鱼传尺愫
鱼传尺愫 2021-01-14 12:51

I\'m trying to use ASP.NET WebPages to make sense of an existing site which uses static .html files (about 500 of them). Unfortunately, my SEO person is requiring that the

2条回答
  •  孤独总比滥情好
    2021-01-14 13:24

    I happened upon this question while trying to solve the same problem - although in my case, for curiosity's sake.

    Here's what you need in your web.config file:

    
       
          
             
          
       
    
    
       
          
       
    
    

    This isn't enough on its own, though! We need to register the extension with WebPageHttpHandler.
    Normally, you'd be able to do stuff like this in the _AppStart file - unfortunately, when the application starts (i.e when _AppStart executes), it iterates over the items in the SupportedExtensions of WebPageHttpHandler, so we can't actually register the extension in AppStart.
    What I did is I made a new .dll assembly with the PreApplicationStartMethod attribute, as seen here, but you can also do it inside the Global.asax file's Application_Start method.

    Finally, we also need to add "html" as an extension to the RazorCodeLanguage.Languages dictionary, so that the Razor engine can figure out how to compile the template.

    Example Global.asax file:

    <%@ Application Language="C#" %>
    
    

提交回复
热议问题