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.

Requirements

  • .NET Framework 4.6.2
  • 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. * Option 2: Use Web.config to configure PrerenderHttpModule (set UsePrestartForPrenderModule = false), please make sure you use Integrated Mode for application pool.
  • 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: "(baiduspider)|(facebookexternalhit)|(twitterbot)|(rogerbot)|(linkedinbot)|(embedly)|(quora link preview)|(showyoubot)|(outbrain)|(pinterest)|(google\\.com)|(slackbot)|(vkShare)|(W3C_Validator)|(redditbot)|(Applebot)|(WhatsApp)|(flipboard)|(tumblr)|(bitlybot)|(SkypeUriPreview)|(nuzzel)|(Discordbot)|(Google Page Speed)|(x\\-bufferbot)"-->
<!--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.

Sample code

You can download the sample project from:

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

Clone this wiki locally