-
Notifications
You must be signed in to change notification settings - Fork 10
Prerender Middleware for ASP.NET Core
dingyuliang edited this page Feb 12, 2017
·
16 revisions
This is an application level middleware solution for prerender.
- .NETStandard 1.6
- Download from Nuget:
Install-Package DotNetCoreOpen.PrerenderMiddleware
-
Configuration File
Add PrerenderConfiguration.json in your ASP.NET Core project by following below content format:
{
"PrerenderConfiguration":
{
"ServiceUrl": "http://localhost:3000",
"Token": null,
"CrawlerUserAgentPattern": null,
"WhiteListPattern": null,
"BlackListPattern": "lib|css|js",
"AdditionalExtensionPattern": null,
"ProxyUrl": null,
"ProxyPort": 80
}
}
More configuration setting details, please go to Configuration & Check Priority
-
Add code in startup.cs
Step 1: Use AddPrerenderConfig() in ConfigurationBuilder
var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) // Prerender Step 1: Add Prerender configuration Json file. .AddPrerenderConfig() .AddEnvironmentVariables();Step 2: Configure Configuration Option in ServiceCollections
// Prerender Step 2: Add Options. services.AddOptions(); services.ConfigureSection<PrerenderConfiguration>(Configuration);Step 3: Configure Prerender Middleware in IApplicationBuilder
// Prerender Step 3: UsePrerender, before others. app.UsePrerender();
You can download the sample project from:
Test Page: ~/Home/About