Class BackOfficeSecurityAccessor
Default IBackOfficeSecurityAccessor implementation that resolves the backoffice identity from the current HTTP context's request services, with support for System.Threading.AsyncLocal<T>-based overrides for background processing scenarios where no HTTP context is available.
Inheritance
Namespace: Umbraco.Cms.Web.Common.Security
Assembly: Umbraco.Web.Common.dll
Syntax
public class BackOfficeSecurityAccessor : IBackOfficeSecurityAccessor
Constructors
View SourceBackOfficeSecurityAccessor(IHttpContextAccessor)
Initializes a new instance of the BackOfficeSecurityAccessor class.
Declaration
public BackOfficeSecurityAccessor(IHttpContextAccessor httpContextAccessor)
Parameters
| Type | Name | Description |
|---|---|---|
| IHttpContextAccessor | httpContextAccessor |
Properties
View SourceBackOfficeSecurity
Gets the current IBackOfficeSecurity object.
Declaration
public IBackOfficeSecurity? BackOfficeSecurity { get; }
Property Value
| Type | Description |
|---|---|
| IBackOfficeSecurity |
Remarks
Returns the ambient override if one has been set for the current async flow via Override(IBackOfficeSecurity), otherwise resolves from the HTTP context's request services. RequestServices can be null when testing, even though compiler says it can't.
Methods
View SourceOverride(IBackOfficeSecurity)
Sets an ambient IBackOfficeSecurity override for the current async flow. The override takes precedence over the HTTP-context-based resolution for the lifetime of the returned scope. Disposing the scope clears the override.
Declaration
public IDisposable Override(IBackOfficeSecurity backOfficeSecurity)
Parameters
| Type | Name | Description |
|---|---|---|
| IBackOfficeSecurity | backOfficeSecurity | The identity to use for the duration of the scope. |
Returns
| Type | Description |
|---|---|
| IDisposable | An System.IDisposable that clears the override when disposed. |
Remarks
This is intended for background processing scenarios where no HTTP context is available but CMS code still needs a backoffice identity.