Table of Contents

Class WebServer

Namespace
nanoFramework.WebServer
Assembly
nanoFramework.WebServer.dll

This class instantiates a web server.

public class WebServer : IDisposable
Inheritance
WebServer
Implements
Inherited Members
Extension Methods

Constructors

WebServer(int, HttpProtocol)

Instantiates a new web server.

public WebServer(int port, HttpProtocol protocol)

Parameters

port int

Port number to listen on.

protocol HttpProtocol

HttpProtocol version to use with web server.

WebServer(int, HttpProtocol, Type[])

Instantiates a new web server.

public WebServer(int port, HttpProtocol protocol, Type[] controllers)

Parameters

port int

Port number to listen on.

protocol HttpProtocol

HttpProtocol version to use with web server.

controllers Type[]

Controllers to use with this web server.

Fields

ParamEqual

URL parameter equal character

public const char ParamEqual = '='

Field Value

char

ParamSeparator

URL parameter separation character

public const char ParamSeparator = '&'

Field Value

char

ParamStart

URL parameter start character

public const char ParamStart = '?'

Field Value

char

Properties

ApiKey

Default APiKey to be used for authentication when no key is specified in the attribute

public string ApiKey { get; set; }

Property Value

string

Credential

Network credential used for default user:password couple during basic authentication

public NetworkCredential Credential { get; set; }

Property Value

NetworkCredential

HttpsCert

The Https certificate to use

public X509Certificate HttpsCert { get; set; }

Property Value

X509Certificate

IsRunning

Gets a value indicating whether the web server is running.

public bool IsRunning { get; }

Property Value

bool

Port

Gets or sets the port the server listens on.

public int Port { get; protected set; }

Property Value

int

Protocol

The type of Http protocol used, http or https

public HttpProtocol Protocol { get; protected set; }

Property Value

HttpProtocol

SslProtocols

SSL protocols

public SslProtocols SslProtocols { get; set; }

Property Value

SslProtocols

Methods

DecodeParam(string)

Get an array of parameters from a URL

public static UrlParameter[] DecodeParam(string parameter)

Parameters

parameter string

Returns

UrlParameter[]

Dispose()

Dispose of any resources.

public void Dispose()

Dispose(bool)

Release resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Dispose of resources?

InvokeRoute(CallbackRoutes, HttpListenerContext)

Method which invokes route. Can be overriden to inject custom logic.

protected virtual void InvokeRoute(CallbackRoutes route, HttpListenerContext context)

Parameters

route CallbackRoutes

Current rounte to invoke. Resolved based on parameters.

context HttpListenerContext

Context of current request.

IsRouteMatch(CallbackRoutes, string, string)

Checks if route matches called resource. For internal use only.

public static bool IsRouteMatch(CallbackRoutes route, string method, string rawUrl)

Parameters

route CallbackRoutes

Route to check.

method string

Invoked resource method.

rawUrl string

Invoked resource URL.

Returns

bool

OutPutStream(HttpListenerResponse, string)

Output a stream

public static void OutPutStream(HttpListenerResponse response, string strResponse)

Parameters

response HttpListenerResponse

the socket stream

strResponse string

the stream to output

OutputHttpCode(HttpListenerResponse, HttpStatusCode)

Output an HTTP Code and close the connection

public static void OutputHttpCode(HttpListenerResponse response, HttpStatusCode code)

Parameters

response HttpListenerResponse

the socket stream

code HttpStatusCode

the http code

SendFileOverHTTP(HttpListenerResponse, string, byte[], string)

Send file content over HTTP response.

public static void SendFileOverHTTP(HttpListenerResponse response, string fileName, byte[] content, string contentType = "")

Parameters

response HttpListenerResponse

HttpListenerResponse to send the content over.

fileName string

Name of the file to send over HttpListenerResponse.

content byte[]

Content of the file to send.

contentType string

The type of file, if empty string, then will use auto detection.

SendFileOverHTTP(HttpListenerResponse, string, string)

Return a file from Storage over HTTP response.

public static void SendFileOverHTTP(HttpListenerResponse response, string strFilePath, string contentType = "")

Parameters

response HttpListenerResponse

HttpListenerResponse to send the content over.

strFilePath string

The file to send

contentType string

The type of file, if empty string, then will use auto detection

Start()

Start the multi threaded server.

public bool Start()

Returns

bool

Stop()

Stop the multi threaded server.

public void Stop()

Events

CommandReceived

CommandReceived event is triggered when a valid command (plus parameters) is received. Valid commands are defined in the AllowedCommands property.

public event WebServer.GetRequestHandler CommandReceived

Event Type

WebServer.GetRequestHandler

WebServerStatusChanged

Occurs when the status of the WebServer changes.

public event WebServer.WebServerStatusHandler WebServerStatusChanged

Event Type

WebServer.WebServerStatusHandler