Skip to content

Prerender Middleware for ASP.NET

dingyuliang edited this page Feb 12, 2017 · 33 revisions

This is an application level middleware solution for prerender. This can be used for both ASP.NET WebForm and MVC.

Requirements

  • .NET Framework 4.0
  • Microsoft.Web.Infrastructure (>= 1.0.0)

User Guide

Download from Nuget:

Install-Package DotNetOpen.PrerenderModule

Configure PrerenderHttpModule in your ASP.NET or ASP.NET MVC project, there are two ways to configure:

  • Option 1: Use UsePrestartForPrenderModule app setting. Once UsePrestartForPrenderModule is true, it means we will use PreApplicationStartMethodAttribute to dynamically load the http module.

    <add key="UsePrestartForPrenderModule" value="true" />
    
  • Option 2: Use Web.config to configure PrerenderHttpModule (set UsePrestartForPrenderModule = false), please make sure you use Integrated Mode for application pool.

    <add key="UsePrestartForPrenderModule" value="false" />
    

Configure web.config for prerender options.

  • Add Configuration Section
<section name="prerender" type="DotNetOpen.PrerenderModule.Configuration.PrerenderConfigurationSection, DotNetOpen.PrerenderModule" />
  • Add Configuration Element
<!--prerender settings-->
<!--CrawlerUserAgentPattern: "(google)|(bing)|(Slurp)|(DuckDuckBot)|(YandexBot)|(baiduspider)|(Sogou)|(Exabot)
|(ia_archiver)|(facebot)|(facebook)|(twitterbot)|(rogerbot)|(linkedinbot)|(embedly)|(quora)|(pinterest)|(slackbot)
|(redditbot)|(Applebot)|(WhatsApp)|(flipboard)|(tumblr)|(bitlybot)|(Discordbot)"-->
<!--WhiteListPattern, BlackListPattern: will check raw URL, which includes query string-->
<!--AdditionalExtensionPattern: will only check extension-->
<prerender ServiceUrl="http://localhost:3000" 
           Token="" 
           WhiteListPattern="" 
           BlackListPattern="" 
           AdditionalExtensionPattern="" 
           ProxyUrl="" 
           ProxyPort="80">
</prerender>

If you want to add your own CrawlerUserAgentPattern which is different from default, you can add an attribute on prerender element; Otherwise, don't add CrawlerUserAgentPattern attribute.

More configuration setting details, please go to Configuration & Check Priority

Sample code

You can download the sample project from:

https://github.com/dingyuliang/prerender-dotnet/tree/master/src/DotNetPrerender/DotNetOpen.PrerenderModule.Mvc

Test Page: ~/Home/About

Clone this wiki locally