DataWeb
Search Results for

    Show / Hide Table of Contents

    Class DisableHotlinkingAttribute.DisableHotlinkingFilter

    Authorization filter created by DisableHotlinkingAttribute via TypeFilterAttribute. Resolves IHttpService from the request service container to obtain the application base URL, then compares it against the Referer header to determine whether the request originates from an external domain.

    Inheritance
    object
    DisableHotlinkingAttribute.DisableHotlinkingFilter
    Implements
    IAsyncActionFilter
    IFilterMetadata
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: DataWeb.Filter
    Assembly: DataWeb.Core.dll
    Syntax
    public class DisableHotlinkingAttribute.DisableHotlinkingFilter : IAsyncActionFilter, IFilterMetadata
    Remarks

    The placeholder image is read from disk on every blocked request. Consider caching the image bytes in memory to avoid repeated I/O under high load.

    IHttpService is resolved via GetRequiredService<T>(IServiceProvider) rather than constructor injection because the service lifetime is scoped to the current HTTP request.

    Constructors

    DisableHotlinkingFilter(IWebHostEnvironment)

    Authorization filter created by DisableHotlinkingAttribute via TypeFilterAttribute. Resolves IHttpService from the request service container to obtain the application base URL, then compares it against the Referer header to determine whether the request originates from an external domain.

    Declaration
    public DisableHotlinkingFilter(IWebHostEnvironment webHostEnvironment)
    Parameters
    Type Name Description
    IWebHostEnvironment webHostEnvironment

    Provides access to WebRootPath to locate the placeholder image.

    Remarks

    The placeholder image is read from disk on every blocked request. Consider caching the image bytes in memory to avoid repeated I/O under high load.

    IHttpService is resolved via GetRequiredService<T>(IServiceProvider) rather than constructor injection because the service lifetime is scoped to the current HTTP request.

    Methods

    OnActionExecutionAsync(ActionExecutingContext, ActionExecutionDelegate)

    Intercepts the action execution to enforce hotlink protection. If the Referer header is present and does not match the application base URL, the pipeline is short-circuited and the placeholder image (or 404) is returned. If the Referer is absent or matches the application URL, execution continues normally.

    Declaration
    public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
    Parameters
    Type Name Description
    ActionExecutingContext context

    The ActionExecutingContext for the current request.

    ActionExecutionDelegate next

    The delegate to invoke to continue the action execution pipeline.

    Returns
    Type Description
    Task

    A Task representing the asynchronous operation.

    Implements

    IAsyncActionFilter
    IFilterMetadata
    In this article
    Back to top Generated by DocFX