---
title: "Class HttpLayoutRequestHandlerBuilderExtensions"
slug: "sitecore.layoutservice.client.extensions.httplayoutrequesthandlerbuilderextensions"
abstract: ""
---
# Class HttpLayoutRequestHandlerBuilderExtensions

Extension methods to support configuration of layout service request handler services.

## Inheritance

System.Object

HttpLayoutRequestHandlerBuilderExtensions

### **Namespace**: Sitecore.LayoutService.Client.Extensions

#### **Assembly**: Sitecore.LayoutService.Client.dll

##### Syntax

```csharp
public static class HttpLayoutRequestHandlerBuilderExtensions : Object

```

### Methods

#### AddHttpHandler(ISitecoreLayoutClientBuilder, String, Action<IServiceProvider, HttpClient>)

Registers a HTTP request handler for the Sitecore layout service client.

##### Declaration

```csharp
public static ILayoutRequestHandlerBuilder<HttpLayoutRequestHandler> AddHttpHandler(this ISitecoreLayoutClientBuilder builder, string handlerName, Action<IServiceProvider, HttpClient> configure)

```

##### Parameters

| Type | Name | Description |
| --- | --- | --- |
| ISitecoreLayoutClientBuilder | builder | The [ISitecoreLayoutClientBuilder](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.isitecorelayoutclientbuilder.html) to configure. |
| System.String | handlerName | The name of the request handler being registered. |
| System.Action<br><br><<br><br>System.IServiceProvider<br><br>,<br><br>System.Net.Http.HttpClient<br><br>> | configure | An action to configure the System.Net.Http.HttpClient. |

##### Returns

| Type | Description |
| --- | --- |
| ILayoutRequestHandlerBuilder<br><br><<br><br>HttpLayoutRequestHandler<br><br>> | The [ILayoutRequestHandlerBuilder<THandler>](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.ilayoutrequesthandlerbuilder-1.html) so that additional calls can be chained. |

#### AddHttpHandler(ISitecoreLayoutClientBuilder, String, Action<HttpClient>)

Registers a HTTP request handler for the Sitecore layout service client.

##### Declaration

```csharp
public static ILayoutRequestHandlerBuilder<HttpLayoutRequestHandler> AddHttpHandler(this ISitecoreLayoutClientBuilder builder, string handlerName, Action<HttpClient> configure)

```

##### Parameters

| Type | Name | Description |
| --- | --- | --- |
| ISitecoreLayoutClientBuilder | builder | The [ISitecoreLayoutClientBuilder](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.isitecorelayoutclientbuilder.html) to configure. |
| System.String | handlerName | The name of the request handler being registered. |
| System.Action<br><br><<br><br>System.Net.Http.HttpClient<br><br>> | configure | An action to configure the System.Net.Http.HttpClient. |

##### Returns

| Type | Description |
| --- | --- |
| ILayoutRequestHandlerBuilder<br><br><<br><br>HttpLayoutRequestHandler<br><br>> | The [ILayoutRequestHandlerBuilder<THandler>](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.ilayoutrequesthandlerbuilder-1.html) so that additional calls can be chained. |

#### AddHttpHandler(ISitecoreLayoutClientBuilder, String, Func<IServiceProvider, HttpClient>)

Registers a HTTP request handler for the Sitecore layout service client.

##### Declaration

```csharp
public static ILayoutRequestHandlerBuilder<HttpLayoutRequestHandler> AddHttpHandler(this ISitecoreLayoutClientBuilder builder, string handlerName, Func<IServiceProvider, HttpClient> resolveClient)

```

##### Parameters

| Type | Name | Description |
| --- | --- | --- |
| ISitecoreLayoutClientBuilder | builder | The [ISitecoreLayoutClientBuilder](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.isitecorelayoutclientbuilder.html) to configure. |
| System.String | handlerName | The name of the request handler being registered. |
| System.Func<br><br><<br><br>System.IServiceProvider<br><br>,<br><br>System.Net.Http.HttpClient<br><br>> | resolveClient | A function to resolve the System.Net.Http.HttpClient to be used. Be aware, that the the underlying System.Net.Http.HttpMessageHandler associated to the HttpClient will be reused across multiple sessions. To prevent data, leaking among sessions, make sure Cookies are not cached. See for reference [https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1#cookies](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1#cookies) . |

##### Returns

| Type | Description |
| --- | --- |
| ILayoutRequestHandlerBuilder<br><br><<br><br>HttpLayoutRequestHandler<br><br>> | The [ILayoutRequestHandlerBuilder<THandler>](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.ilayoutrequesthandlerbuilder-1.html) so that additional calls can be chained. |

#### AddHttpHandler(ISitecoreLayoutClientBuilder, String, Func<IServiceProvider, HttpClient>, String\[\])

Registers a HTTP request handler for the Sitecore layout service client.

##### Declaration

```csharp
public static ILayoutRequestHandlerBuilder<HttpLayoutRequestHandler> AddHttpHandler(this ISitecoreLayoutClientBuilder builder, string handlerName, Func<IServiceProvider, HttpClient> resolveClient, string[] nonValidatedHeaders)

```

##### Parameters

| Type | Name | Description |
| --- | --- | --- |
| ISitecoreLayoutClientBuilder | builder | The [ISitecoreLayoutClientBuilder](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.isitecorelayoutclientbuilder.html) to configure. |
| System.String | handlerName | The name of the request handler being registered. |
| System.Func<br><br><<br><br>System.IServiceProvider<br><br>,<br><br>System.Net.Http.HttpClient<br><br>> | resolveClient | A function to resolve the System.Net.Http.HttpClient to be used. Be aware, that the the underlying System.Net.Http.HttpMessageHandler associated to the HttpClient will be reused across multiple sessions. To prevent data, leaking among sessions, make sure Cookies are not cached. See for reference [https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1#cookies](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1#cookies) . |
| System.String<br><br>[] | nonValidatedHeaders | The list of headers which should not be validated. |

##### Returns

| Type | Description |
| --- | --- |
| ILayoutRequestHandlerBuilder<br><br><<br><br>HttpLayoutRequestHandler<br><br>> | The [ILayoutRequestHandlerBuilder<THandler>](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.ilayoutrequesthandlerbuilder-1.html) so that additional calls can be chained. |

#### AddHttpHandler(ISitecoreLayoutClientBuilder, String, String)

Registers a HTTP request handler for the Sitecore layout service client.

##### Declaration

```csharp
public static ILayoutRequestHandlerBuilder<HttpLayoutRequestHandler> AddHttpHandler(this ISitecoreLayoutClientBuilder builder, string handlerName, string uri)

```

##### Parameters

| Type | Name | Description |
| --- | --- | --- |
| ISitecoreLayoutClientBuilder | builder | The [ISitecoreLayoutClientBuilder](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.isitecorelayoutclientbuilder.html) to configure. |
| System.String | handlerName | The name of the request handler being registered. |
| System.String | uri | The System.Uri used for the System.Net.Http.HttpClient.BaseAddress. |

##### Returns

| Type | Description |
| --- | --- |
| ILayoutRequestHandlerBuilder<br><br><<br><br>HttpLayoutRequestHandler<br><br>> | The [ILayoutRequestHandlerBuilder<THandler>](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.ilayoutrequesthandlerbuilder-1.html) so that additional calls can be chained. |

#### AddHttpHandler(ISitecoreLayoutClientBuilder, String, Uri)

Registers a HTTP request handler for the Sitecore layout service client.

##### Declaration

```csharp
public static ILayoutRequestHandlerBuilder<HttpLayoutRequestHandler> AddHttpHandler(this ISitecoreLayoutClientBuilder builder, string handlerName, Uri uri)

```

##### Parameters

| Type | Name | Description |
| --- | --- | --- |
| ISitecoreLayoutClientBuilder | builder | The [ISitecoreLayoutClientBuilder](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.isitecorelayoutclientbuilder.html) to configure. |
| System.String | handlerName | The name of the request handler being registered. |
| System.Uri | uri | The System.Uri used for the System.Net.Http.HttpClient.BaseAddress. |

##### Returns

| Type | Description |
| --- | --- |
| ILayoutRequestHandlerBuilder<br><br><<br><br>HttpLayoutRequestHandler<br><br>> | The [ILayoutRequestHandlerBuilder<THandler>](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.ilayoutrequesthandlerbuilder-1.html) so that additional calls can be chained. |

#### ConfigureRequest(ILayoutRequestHandlerBuilder<HttpLayoutRequestHandler>, String\[\])

Adds default configuration for the HTTP request message.

##### Declaration

```csharp
public static ILayoutRequestHandlerBuilder<HttpLayoutRequestHandler> ConfigureRequest(this ILayoutRequestHandlerBuilder<HttpLayoutRequestHandler> httpHandlerBuilder, string[] nonValidatedHeaders)

```

##### Parameters

| Type | Name | Description |
| --- | --- | --- |
| ILayoutRequestHandlerBuilder<br><br><<br><br>HttpLayoutRequestHandler<br><br>> | httpHandlerBuilder | The [ILayoutRequestHandlerBuilder<THandler>](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.ilayoutrequesthandlerbuilder-1.html) to configure. |
| System.String<br><br>[] | nonValidatedHeaders | The list of headers which should not be validated. |

##### Returns

| Type | Description |
| --- | --- |
| ILayoutRequestHandlerBuilder<br><br><<br><br>HttpLayoutRequestHandler<br><br>> | The [ILayoutRequestHandlerBuilder<THandler>](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.ilayoutrequesthandlerbuilder-1.html) so that additional calls can be chained. |

#### MapFromRequest(ILayoutRequestHandlerBuilder<HttpLayoutRequestHandler>, Action<SitecoreLayoutRequest, HttpRequestMessage>)

Registers a System.Net.Http.HttpRequestMessage configuration action as named [HttpLayoutRequestHandlerOptions](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.httplayoutrequesthandleroptions.html) for the given handler.

##### Declaration

```csharp
public static ILayoutRequestHandlerBuilder<HttpLayoutRequestHandler> MapFromRequest(this ILayoutRequestHandlerBuilder<HttpLayoutRequestHandler> builder, Action<SitecoreLayoutRequest, HttpRequestMessage> configureHttpRequestMessage)

```

##### Parameters

| Type | Name | Description |
| --- | --- | --- |
| ILayoutRequestHandlerBuilder<br><br><<br><br>HttpLayoutRequestHandler<br><br>> | builder | The [ILayoutRequestHandlerBuilder<THandler>](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.ilayoutrequesthandlerbuilder-1.html) to configure. |
| System.Action<br><br><<br><br>SitecoreLayoutRequest<br><br>,<br><br>System.Net.Http.HttpRequestMessage<br><br>> | configureHttpRequestMessage | The System.Net.Http.HttpRequestMessage configuration based on [SitecoreLayoutRequest](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.request.sitecorelayoutrequest.html). |

##### Returns

| Type | Description |
| --- | --- |
| ILayoutRequestHandlerBuilder<br><br><<br><br>HttpLayoutRequestHandler<br><br>> | The configured [ILayoutRequestHandlerBuilder<THandler>](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-asp-dot-net-rendering-sdk/sitecore.layoutservice.client.ilayoutrequesthandlerbuilder-1.html). |
