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
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
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
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
See Also
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
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
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 |
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 |
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 |
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 |
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
Start(CancellationToken)
Signals a module that the web server is starting.
Declaration
public void Start(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | A |
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. |