Troubleshooting applications created with the ASP.NET Rendering SDK
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 theAddHttpHandler
extension method as thenonValidatedHeaders
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:
In the
appsettings.json
file, specify a new property with an array of strings as a value. For example:"Sitecore": { "HeadersToSkipValidation": ["User-Agent"] }
In the
\Configuration\SitecoreOptions.cs
file, specify the new property:public class SitecoreOptions{ // ... public string[] HeadersToSkipValidation { get; set; } = new string[0]; // ... }
Finally, in the
Startup.cs
file, use theAddHttpHandler
extension method and provide the array of headers as thenonValidatedHeaders
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