Unosquare
    Show / Hide Table of Contents

    Class WebModuleBase

    Base class to define web modules.

    Although it is not required that a module inherits from this class, it provides some useful features:

    • validation and immutability of the BaseRoute property, which are of paramount importance for the correct functioning of a web server;
    • support for configuration locking upon web server startup (see the property and the method);
    • a basic implementation of the Start(CancellationToken) method for modules that do not need to do anything upon web server startup;
    • implementation of the OnUnhandledException callback property.

    Inheritance
    Object
    WebModuleBase
    ActionModule
    RedirectModule
    AuthenticationModuleBase
    CorsModule
    FileModule
    ModuleGroup
    RoutingModuleBase
    IPBanningModule
    WebSocketModule
    Implements
    IWebModuleImpl
    IWebModule
    Namespace: EmbedIO
    Syntax
    public abstract class WebModuleBase : ConfiguredObject, IWebModuleImpl, IWebModule

    Constructors

    WebModuleBase(String)

    Initializes a new instance of the WebModuleBase class.

    Declaration
    protected WebModuleBase(string baseRoute)
    Parameters
    Type Name Description
    String baseRoute

    The base route served by this module.

    See Also
    BaseRoute

    Properties

    BaseRoute

    Gets the base route of a module.

    Declaration
    public string BaseRoute { get; }
    Property Value
    Type Description
    String

    The base route.

    Remarks

    A base route is either "/" (the root path), or a prefix starting and ending with a '/' character.

    Container

    Gets the container of this module.

    Declaration
    public IWebModuleContainer Container { get; }
    Property Value
    Type Description
    IWebModuleContainer
    See Also
    IWebModuleContainer

    IsFinalHandler

    Gets a value indicating whether processing of a request should stop after a module has handled it.

    Declaration
    public abstract bool IsFinalHandler { get; }
    Property Value
    Type Description
    Boolean
    Remarks

    If this property is true, a HTTP context's SetHandled() method will be automatically called immediately after after the returned by HandleRequestAsync(IHttpContext) is completed. This will prevent the context from being passed further along to other modules.

    See Also
    IsHandled
    SetHandled()

    LogSource

    Gets a string to use as a source for log messages.

    Declaration
    protected string LogSource { get; }
    Property Value
    Type Description
    String

    OnHttpException

    Gets or sets a callback that is called every time a HTTP exception is thrown during the processing of a request.

    If this property is null (the default), the exception will be handled by the web server, or by the containing ModuleGroup.

    Declaration
    public HttpExceptionHandlerCallback OnHttpException { get; set; }
    Property Value
    Type Description
    HttpExceptionHandlerCallback
    See Also
    HttpExceptionHandler

    OnUnhandledException

    Gets or sets a callback that is called every time an unhandled exception occurs during the processing of a request.

    If this property is null (the default), the exception will be handled by the web server, or by the containing ModuleGroup.

    Declaration
    public ExceptionHandlerCallback OnUnhandledException { get; set; }
    Property Value
    Type Description
    ExceptionHandlerCallback
    See Also
    ExceptionHandler

    Methods

    HandleRequestAsync(IHttpContext)

    Handles a request from a client.

    Declaration
    public Task HandleRequestAsync(IHttpContext context)
    Parameters
    Type Name Description
    IHttpContext context

    The context of the request being handled.

    Returns
    Type Description
    Task

    A representing the ongoing operation.

    MatchUrlPath(String)

    Matches the specified URL path against a module's BaseRoute, extracting values for the route's parameters and a sub-path.

    Declaration
    public RouteMatch MatchUrlPath(string path)
    Parameters
    Type Name Description
    String path

    The URL path to match.

    Returns
    Type Description
    RouteMatch

    If the match is successful, a object; otherwise, null.

    OnRequestAsync(IHttpContext)

    Called to handle a request from a client.

    Declaration
    protected abstract Task OnRequestAsync(IHttpContext context)
    Parameters
    Type Name Description
    IHttpContext context

    The context of the request being handled.

    Returns
    Type Description
    Task

    A representing the ongoing operation.

    OnStart(CancellationToken)

    Called when a module is started, immediately before locking the module's configuration.

    Declaration
    protected virtual void OnStart(CancellationToken cancellationToken)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    A used to stop the web server.

    SetContainer(IWebModuleContainer)

    Sets the container of this module.

    This API supports the EmbedIO infrastructure; it is not intended to be used directly from your code.

    Declaration
    protected void SetContainer(IWebModuleContainer value)
    Parameters
    Type Name Description
    IWebModuleContainer value

    The container to associate this module with.

    See Also
    Container
    IWebModuleContainer

    Start(CancellationToken)

    Signals a module that the web server is starting.

    Declaration
    public void Start(CancellationToken cancellationToken)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    A used to stop the web server.

    Remarks

    The module's configuration is locked before returning from this method.

    Explicit Interface Implementations

    IWebModuleImpl.SetContainer(IWebModuleContainer)

    Sets the container of this module.

    This API supports the EmbedIO infrastructure; it is not intended to be used directly from your code.

    Declaration
    void IWebModuleImpl.SetContainer(IWebModuleContainer value)
    Parameters
    Type Name Description
    IWebModuleContainer value

    The container to associate this module with.

    See Also
    Container
    IWebModuleContainer

    Implements

    IWebModuleImpl
    IWebModule

    Comments

    Back to top Copyright © 2017-2019 Unosquare