Stott.Optimizely.RobotsHandler 2.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Stott.Optimizely.RobotsHandler --version 2.3.0
NuGet\Install-Package Stott.Optimizely.RobotsHandler -Version 2.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Stott.Optimizely.RobotsHandler" Version="2.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Stott.Optimizely.RobotsHandler --version 2.3.0
#r "nuget: Stott.Optimizely.RobotsHandler, 2.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Stott.Optimizely.RobotsHandler as a Cake Addin
#addin nuget:?package=Stott.Optimizely.RobotsHandler&version=2.3.0

// Install Stott.Optimizely.RobotsHandler as a Cake Tool
#tool nuget:?package=Stott.Optimizely.RobotsHandler&version=2.3.0

Stott.Optimizely.RobotsHandler

Platform Platform GitHub GitHub Workflow Status Nuget

This is a new admin extension for Optimizely CMS 12+ for managing robots.txt on a per site basis. The Stott.Optimizely.RobotsHandler project is a Razor Class Library which contains Razor Files, static JS files and relevent business logic specific to this functionality.

Configuration

Startup.cs

After pulling in a reference to the Stott.Optimizely.RobotsHandler project, you need to ensure the following lines are added to the startup class of your solution:

public void ConfigureServices(IServiceCollection services)
{
    services.AddRazorPages();
    services.AddRobotsHandler();
}

The call to services.AddRazorPages() is a standard .NET call to ensure razor pages are included in your solution.

The call to services.AddRobotsHandler() sets up the dependency injection requirements for the RobotsHandler solution and is required to ensure the solution works as intended. This works by following the Services Extensions pattern defined by microsoft.

Program.cs

As this package includes static files such as JS and CSS files within the Razor Class Library, your solution must be configured to use Static Web Assets. This is done by adding webBuilder.UseStaticWebAssets(); to your Program.cs as follows:

Host.CreateDefaultBuilder(args)
    .ConfigureCmsDefaults()
    .ConfigureWebHostDefaults(webBuilder =>
    {
        webBuilder.UseStartup<Startup>();
        webBuilder.UseStaticWebAssets();
    });

You can read more about shared assets in Razor Class Libraries here: Create reusable UI using the Razor class library project in ASP.NET Core

Adding Robots Admin to the menus.

This solution also includes an implementation of IMenuProvider which ensures that the Robots Handler administration pages are included in the CMS Admin menu under the title of "Robots". You do not have to do anything to make this work as Optimizely CMS will scan and action all implementations of IMenuProvider.

Authorisation Configuration

The configuration of the module has some scope for modification by providing configuration in the service extension methods. The provision of authorizationOptions is optional in the following example.

Example:

services.AddRobotsHandler(authorizationOptions => 
{
    authorizationOptions.AddPolicy(RobotsConstants.AuthorizationPolicy, policy =>
    {
        policy.RequireRole("WebAdmins");
    });
});

If the authorizationOptions is not provided, then any of the following roles will be required be default:

  • CmsAdmins
  • Administrator
  • WebAdmins

Contributing

I am open to contributions to the code base. The following rules should be followed:

  1. Contributions should be made by Pull Requests.
  2. All commits should have a meaningful messages.
  3. All commits should have a reference to your GitHub user.
  4. Ideally all new changes should include appropriate unit test coverage.

Common Issues

RobotsAdmin.js returns a 404 error response.

The RobotsHandler is built as a Razor Class Library, this produces a manifest that tells the application about the static assets that are included within the Razor Class Library. This is solved by adding webBuilder.UseStaticWebAssets(); to the ConfigureWebHostDefaults method in Program.cs. Please see the configuration section above.

Projects that do not use Razor MVC lead to missing assets

Stott.Optimizely.RobotsHandler has been built as a Razor Class Library, this is predicated on a build being compatible with Razor MVC. If your build does not use Razor MVC and the build pipeline does not inclue the output of such, then this can cause the admin interface not to work. In this scenario this will require you to update your build pipeline to include these assets.

The following is a YAML example cloned from a screenshot where this problem was resolved:

- task: CopyFiles@2
  inputs:
    SourceFolder: '$(projectName)/obj/$(BuildConfiguration)/net6.0/PubTmp/Out/wwwrooot'
    Contents: '**'
    CleanTargetFolder: false
    TargetFolder: '$(Agent.TempDirectory)/$(today)/wwwroot/wwwroot/'

A big thank you goes to Praveen Soni who helped identify this as an issue.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.7.0 2,691 2/17/2024
2.6.2 12,624 10/12/2023
2.6.1 18,469 4/10/2023
2.5.0 10,707 2/8/2023
2.4.0 6,259 1/11/2023
2.3.0 4,396 11/7/2022
2.2.0 3,362 10/30/2022
2.1.0 6,652 9/21/2022
2.0.0 4,446 8/5/2022

Allow users to reach robots.txt without needing to log into the CMS. Move robots into the main menu to allow security for robots.txt to be configured without requiring CMS Admin access.