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
portintPort number to listen on.
protocolHttpProtocolHttpProtocol version to use with web server.
WebServer(int, HttpProtocol, Type[])
Instantiates a new web server.
public WebServer(int port, HttpProtocol protocol, Type[] controllers)
Parameters
portintPort number to listen on.
protocolHttpProtocolHttpProtocol version to use with web server.
controllersType[]Controllers to use with this web server.
Fields
ParamEqual
URL parameter equal character
public const char ParamEqual = '='
Field Value
ParamSeparator
URL parameter separation character
public const char ParamSeparator = '&'
Field Value
ParamStart
URL parameter start character
public const char ParamStart = '?'
Field Value
Properties
ApiKey
Default APiKey to be used for authentication when no key is specified in the attribute
public string ApiKey { get; set; }
Property Value
Credential
Network credential used for default user:password couple during basic authentication
public NetworkCredential Credential { get; set; }
Property Value
HttpsCert
The Https certificate to use
public X509Certificate HttpsCert { get; set; }
Property Value
IsRunning
Gets a value indicating whether the web server is running.
public bool IsRunning { get; }
Property Value
Port
Gets or sets the port the server listens on.
public int Port { get; protected set; }
Property Value
Protocol
The type of Http protocol used, http or https
public HttpProtocol Protocol { get; protected set; }
Property Value
SslProtocols
SSL protocols
public SslProtocols SslProtocols { get; set; }
Property Value
Methods
DecodeParam(string)
Get an array of parameters from a URL
public static UrlParameter[] DecodeParam(string parameter)
Parameters
parameterstring
Returns
Dispose()
Dispose of any resources.
public void Dispose()
Dispose(bool)
Release resources.
protected virtual void Dispose(bool disposing)
Parameters
disposingboolDispose 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
routeCallbackRoutesCurrent rounte to invoke. Resolved based on parameters.
contextHttpListenerContextContext 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
routeCallbackRoutesRoute to check.
methodstringInvoked resource method.
rawUrlstringInvoked resource URL.
Returns
OutPutStream(HttpListenerResponse, string)
Output a stream
public static void OutPutStream(HttpListenerResponse response, string strResponse)
Parameters
responseHttpListenerResponsethe socket stream
strResponsestringthe stream to output
OutputHttpCode(HttpListenerResponse, HttpStatusCode)
Output an HTTP Code and close the connection
public static void OutputHttpCode(HttpListenerResponse response, HttpStatusCode code)
Parameters
responseHttpListenerResponsethe socket stream
codeHttpStatusCodethe 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
responseHttpListenerResponseHttpListenerResponse to send the content over.
fileNamestringName of the file to send over HttpListenerResponse.
contentbyte[]Content of the file to send.
contentTypestringThe 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
responseHttpListenerResponseHttpListenerResponse to send the content over.
strFilePathstringThe file to send
contentTypestringThe type of file, if empty string, then will use auto detection
Start()
Start the multi threaded server.
public bool Start()
Returns
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
WebServerStatusChanged
Occurs when the status of the WebServer changes.
public event WebServer.WebServerStatusHandler WebServerStatusChanged