Skip to main content

Troubleshooting applications created with the ASP.NET Rendering SDK

Abstract

Investigate and resolve issues in your ASP.NET rendering hosts.

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

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:

    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:

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

    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:

    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