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
intPort number to listen on.
protocol
HttpProtocolHttpProtocol 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
intPort number to listen on.
protocol
HttpProtocolHttpProtocol 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
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
parameter
string
Returns
Dispose()
Dispose of any resources.
public void Dispose()
Dispose(bool)
Release resources.
protected virtual void Dispose(bool disposing)
Parameters
disposing
boolDispose 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
CallbackRoutesCurrent rounte to invoke. Resolved based on parameters.
context
HttpListenerContextContext 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
CallbackRoutesRoute to check.
method
stringInvoked resource method.
rawUrl
stringInvoked resource URL.
Returns
OutPutStream(HttpListenerResponse, string)
Output a stream
public static void OutPutStream(HttpListenerResponse response, string strResponse)
Parameters
response
HttpListenerResponsethe socket stream
strResponse
stringthe stream to output
OutputHttpCode(HttpListenerResponse, HttpStatusCode)
Output an HTTP Code and close the connection
public static void OutputHttpCode(HttpListenerResponse response, HttpStatusCode code)
Parameters
response
HttpListenerResponsethe socket stream
code
HttpStatusCodethe 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
HttpListenerResponseHttpListenerResponse to send the content over.
fileName
stringName of the file to send over HttpListenerResponse.
content
byte[]Content of the file to send.
contentType
stringThe 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
HttpListenerResponseHttpListenerResponse to send the content over.
strFilePath
stringThe file to send
contentType
stringThe 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