Troubleshooting applications created with the ASP.NET Rendering SDK

Current version: 19.x

This topic describes issues you might encounter in applications created with the ASP.NET Rendering SDK and explains possible solutions.

Handling validation errors for request headers

If you are getting errors about request header validation and are using the Layout Service REST API, you can define a list of headers to be skipped during header validation.

To configure headers that skip the validation process:

  • In the Startup.cs file, provide an array of headers to the AddHttpHandler extension method as the nonValidatedHeaders parameter. For example:

    RequestResponse
    services
         // ...
        .AddHttpHandler("your_handler_name".Name, sp =>
        {
            var factory = sp.GetRequiredService<System.Net.Http.IHttpClientFactory>();
            var client = factory.CreateClient("your_handler_name");
    
            client.BaseAddress = "your_handler_uri";
    
            return client;
    
         }, new [] { "User-Agent" })
        // ...

Alternatively, define the list of headers in the appsettings.json file and provide them as a configuration property:

  1. In the appsettings.json file, specify a new property with an array of strings as a value. For example:

    RequestResponse
    "Sitecore": {
      "HeadersToSkipValidation": ["User-Agent"]
    }
  2. In the \Configuration\SitecoreOptions.cs file, specify the new property:

    RequestResponse
    public class SitecoreOptions{
     // ...
     public string[] HeadersToSkipValidation { get; set; } = new string[0];
     // ...
    } 
  3. Finally, in the Startup.cs file, use the AddHttpHandler extension method and provide the array of headers as the nonValidatedHeaders parameter:

    RequestResponse
    services
    // ... other code
       .AddHttpHandler("<your_handler_name>", sp => 
       {
           var factory = sp.GetRequiredService<System.Net.Http.IHttpClientFactory>();
           var client = factory.CreateClient("default");
           client.BaseAddress = Configuration.LayoutServiceUri;
           return client;
      }, Configuration.HeadersToSkipValidation
    // ... other code 

Do you have some feedback for us?

If you have suggestions for improving this article,