Sitemap and Robots Generator for Optimizely/Episerver CMS 12
This blog post is a continuation to the blog post about the Sitemap and Robots Generator for Episerver CMS, where you can find how to install and configure the plugin, the blog post about the Sitemap and Robots Generator for Commerce Episerver CMS, which explain how to add products to the sitemap file and the blog post about the Sitemap and Robots Generator Filter Programmatically by Type, which explains how you can programmatically filter your sitemap items by type. In here, we are going to explain how we can configure plugin for the new version of the Optimizely/Episerver CMS 12 which uses asp.net core instead of asp.net MVC. For this, we will use the latest version available of the plugin which at the time of writing is 5.0.0.8. From now on, the plugin will use the dot net mayor version as the first identifier in the plugin package version. In this case, 5 is for dot net core 5.0 which is required for CMS 12. You can find the plugin developed by Verndale in this link. If you cannot find the latest version in the episerver feed please use the nuget feed instead.
To begin, we are going to install the package using the Package Management Console and this command
Install-Package Verndale.Sitemap.Robots.Generator -Version 5.0.0.8
Please read carefully the Readme file. Some of the new changes we brought to this version are mentioned in there, but most important, it explains how to configure several parameters of the plugin which we will also explain meticulously later in this post.
After installation, we will copy the following lines to your base page, this is not required, but it is needed if you want more control over the pages that are going to appear in the sitemap, its frequency and priority. Please pay special attention to the comments in the code.
[Display(GroupName = "Navigation",
Name = "Exclude from Xml Site Map",
Order = 400)]
public virtual bool ExcludeFromSiteMap { get; set; } // Exclude this page from the sitemap
[Display(GroupName = "Navigation",
Name = "Priority in Site Map",
Order = 500)]
public virtual string Priority { get; set; } // The priority applied to this page in the sitemap
[Display(GroupName = "Navigation",
Name = "Change Frequency of Page in Site Map",
Order = 600)]
public virtual string ChangeFrequency { get; set; } // The frequency applied to this page in the sitemap
Because, asp.net core does not use handlers anymore you must now add in your startup class or where you initialize your site features. For instance, in the configure method of the startup class.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseSitemapRobotsMiddleware(); // Line to add
}
Next, we need to add the application settings for the plugin in the appsettings.json file. In the previous version we were able to add this automatically using web config transforms but this is not a feature anymore for dot net core nuget packages.
"Siro": {
"Show_Localized_URLS": "true",
"Display_Localized_URLS_Separated": "false",
"Show_Trailing_Slash": "false",
"SiteMap_OutPutRobots_txt": "1"
}
With these changes in your code and configuration files, it is enough to make the plugin work as expected. Now we are going to explain the application settings configurations which you can modify to fit your needs inside the appsettings.json file.
Key | Description |
Show_Localized_URLS (true/false) | If the sitemap is going to show localized urls based on google recommendations with href lang attribute |
Display_Localized_URLS_Separated (true/false) | If the sitemap is going to display the localized urls separated instead of using href lang |
Show_Trailing_Slash (true/false) | Show a trailing slash at the end of each URL in the sitemap |
SiteMap_OutPutRobots_txt (1/0) | If the Sitemap URL is going to be added to the robots content after the sitemap is generated |
The previous version of the plugin for CMS 11 had a sitemap.config file inside the App_Config folder, but we are not using it anymore because it was only used for XML name spaces configurations and those did not change enough to justify the separated file. Finally, this version now properly support middleware for IIS express and Kestrel servers so you can see your sitemap and robots files in those servers.
Finally, to access the configuration section of the plugin, you now have to go to the admin section, and then to the Sitemap & Robots tab next to the tools tab.
And that is it. You can now use the Sitemap and Robots plugin in the new Optimizely/Episerver CMS 12 version without any issues. If you have any questions or suggestions please let me know in the comments. I hope this plugin can help someone and as always keep learning !!!
(Update) From version 5.0.0.9 the issue with duplicated hostnames in the sitemap.xml file should be fixed.
11 COMMENTS