Troubleshooting applications created with the ASP.NET Rendering SDK
If you integrated your ASP.NET Core app before September 2024, it's using the legacy ASP.NET Core Rendering SDK, version 22 or earlier. This SDK is no longer receiving updates, so we recommend that you upgrade to the latest version of the new ASP.NET Core SDK.
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.csfile, provide an array of headers to theAddHttpHandlerextension method as thenonValidatedHeadersparameter. For example:RequestResponseservices // ... .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.jsonfile, specify a new property with an array of strings as a value. For example:RequestResponse"Sitecore": { "HeadersToSkipValidation": ["User-Agent"] } -
In the
\Configuration\SitecoreOptions.csfile, specify the new property:RequestResponsepublic class SitecoreOptions{ // ... public string[] HeadersToSkipValidation { get; set; } = new string[0]; // ... } -
Finally, in the
Startup.csfile, use theAddHttpHandlerextension method and provide the array of headers as thenonValidatedHeadersparameter:RequestResponseservices // ... 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