ModdableWebServer 1.4.0

dotnet add package ModdableWebServer --version 1.4.0
NuGet\Install-Package ModdableWebServer -Version 1.4.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ModdableWebServer" Version="1.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ModdableWebServer --version 1.4.0
#r "nuget: ModdableWebServer, 1.4.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ModdableWebServer as a Cake Addin
#addin nuget:?package=ModdableWebServer&version=1.4.0

// Install ModdableWebServer as a Cake Tool
#tool nuget:?package=ModdableWebServer&version=1.4.0

Moddable Web Server


This project is made because I used more than 2 project the NetCoreServer Library and each project is used to make a Server that support more C# DLL to be loaded.

I am really bad at making a Good Documentation. Please help!

Using the Library


What is ServerStruct?

You only Need to know you can get the Headers, URL Parameters, and can parse a Response to it.

About Headers & Parameters: Duplication is been reduced. (Please do not use same parameter in url.)
Key of it is lowercase

Response Creator

Creating response simple.

Make sure you adding like this:

//here you create a simple 200 (OK) response.
ResponseCreator response = new();
//adding one Header to it.
//adding multiple header to it.
	new Dictionary<string, string>() 
		{ "key", "Value" }

//adding content to it.
response.SetBody("Hello World?");

//Getting the HttpResponse.
_ = response.GetResponse();

//we can use the already made creator for start to make a new one.

If you ever will need, you can use response.SetResponse, but not suggesting it.

Use of HTTPAttribute

[HTTP("Method", "Url")]

In Method can be used any HTTP/S Method.

In the Url you can use the full url, or making it as parameter

[HTTP("GET", "/full/url")]

[HTTP("GET", "/hey/{parameters}")]

Make sure your Function is PUBLIC, STATIC, and must return a BOOL.

[HTTP("GET", "/test")]
public static bool test(HttpRequest request, ServerStruct serverStruct)
	//simple response making
	//And sending the response.
	//return is if the page exist or not. It will try to send 404 if false.
	return true;

Example or Return a false:

[HTTP("GET", "/throw404")]
public static bool throw_404(HttpRequest request, ServerStruct serverStruct)
	return false;


What is WebSocketStruct?

It contains:

  • Request of the Connection.
    • The url.
    • Headers
    • Parameters,
    • Body
  • Is Connected or not.
  • WebSocket Bytes Request (NULLABLE)
  • Two Session for each type (WS,WSS)
  • Enum, which is currently used.

Use of WSAttribute

In the Url you can use the full url, or making it as parameter

Make sure your Function is PUBLIC, STATIC, and must a VOID.

 public static void ws(WebSocketStruct webStruct)
	 //bunch of stuff for printing.
	 //answering in the websocket.

Making a server.

Here you gonna see how we make a server and using it.

Certificate for Secure server.

Make sure you have a PFX file in a disk, and a password for that pfx file (The PFX file must use a password!)

Using Fields Neccesary:

//add this into the before the classname
using System.Security.Authentication;
using ModdableWebServer.Helper;

You can use any SslProtocol for this, I always use TLS 1.2

//Get Context with Validation
CertHelper.GetContext( SslProtocols.Tls12, "mypfx.pfx", "asecurepassword");

//Get Context with No Validation
CertHelper.GetContextNoValidate( SslProtocols.Tls12, "mypfx.pfx", "asecurepassword");


You can use any of it to make a sever

var context = CertHelper.GetContext( SslProtocols.Tls12, "mypfx.pfx", "asecurepassword");
var ws_server = new WS_Server("", 6666);
var wss_server = new WSS_Server(context, "", 6667);
var http_server = new HTTP_Server("", 6668);
var https_server = new HTTPS_Server(context, "", 6669);

Starting and Stopping.

Simply just use Start(), or Stop()



Each HTTP(S) server comes with event like:

public EventHandler<(HttpRequest request, string error)> ReceivedRequestError;
public EventHandler<SocketError> OnSocketError;
public EventHandler<HttpRequest> ReceivedFailed;
public event EventHandler<(string address, int port)> Started;
public event EventHandler Stopped;

WS(S) Only add one:

public EventHandler<string> WSError;

Adding our created Attributes to the Server

Merging (Will fail if other DLL already contains url/method)

// Loading Entry assembly contained HTTP/WS Attribute and merging.

Overriding. It will replace already existing ones.

// Loading Entry assembly contained HTTP/WS Attribute and merging.

Assembly Difference

This is so Technical I needed to check like 5 times.

We have 4 Assembly: ModdableWebServer (MWS)
MyServerLib (Lib)
MyServerExtenstion (Extension)
MyServerConsole (Console)

Console starts a Lib.
Lib starts MWS.
Lib starts Extension.

Extenstion Contain a Class: EXT
Lib Contains a Class: LIBC
Console Contains a Class: CONC

GetEntryAssembly = Console
GetCallingAssembly On Extension = Lib
GetCallingAssembly On Lib = Console
GetExecutingAssembly On Lib = Lib
GetExecutingAssembly On Extension = Extension
GetExecutingAssembly On Console = Console
GetAssembly(typeof(EXT)) = Extension
GetAssembly(typeof(LIBC)) = Lib
GetAssembly(typeof(CONC)) = Console

Use the GetAssembly and TypeOf if you dont know what Assembly loaded what!

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on ModdableWebServer:

Repository Stars
PayDay 3 Server Emulator Attempt
Version Downloads Last updated
1.4.0 116 3/16/2024
1.3.2 153 2/13/2024
1.3.1 112 2/2/2024
1.3.0 94 1/25/2024
1.2.1 165 1/1/2024
1.2.0 112 12/28/2023
1.1.1 330 10/16/2023 184 10/14/2023
1.1.0 152 10/14/2023
1.0.0 144 10/13/2023