Self Hosted

How to run a Wisej app as a self-hosted process or service.

.NET Core

Wisej 3 .NET Core applications are self-hosted by default being standard ASP.NET Core applications. ASP.NET Core apps are built to an executable that you can simply start and will start hosting your application. You don't need to use Wisej.HostService.exe.

πŸ‘‰ If you are deploying on a Linux distribution or on MacOS, make sure libgdiplus is installed.

Basic Steps

  1. Run the publishing tool to deploy to a folder.

That's it. When you run YourApplication.exe you can use the --urls command line argument to configure the application's endpoints.

Service

Wisej 3 ASP.NET Core apps can be deployed as a Windows service quite easily:

  1. Add the WindowsServices nuget to your project.

  2. Add builder.Host.UseWindowsServices() to Startup.cs or Startup.vb (see code snippet below).

  3. Register the service using "sc create"

  4. Now you can start the service like any other Windows service. For any additional configuration option refer to the Microsoft documentation.

var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
  Args = args,
  WebRootPath = "./",

    // Add this:
  ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
});

// And this
builder.Host.UseWindowsService();

...

.NET Framework

You can run a Wisej application (including Wisej 3 on .NET 4.8) as a self hosting process or service. All you need to do is deploy the Wisej.HostService executable in the root folder of the deployment directory.

Basic Steps

  1. Create the application directory

  2. Copy Wisej.HostService.exe to the application directory

  3. Create the /bin directory in the application's directory

  4. Copy all the assemblies from your local /bin to the server's /bin (no need to copy xml and pdb files)

  5. Copy the /Themes folder if you have custom themes or mixins

  6. Copy the /Images folder if you have images that need to be served as URLs

  7. Copy the /App_Data folder if your application uses it

  8. Copy Default.html (and other html files you use sub-applications)

  9. Copy Default.json (and other json configuration files if you use sub-applications)

  10. Copy favicon.ico.

Wisej.HostService is currently only available in GitHub - you need to download the source code and compile the executable.

Once the deployment directory is ready, you can either register Wisej.HostService.exe as a Windows service, or run it directly as a normal process.

Self Hosting uses the classic pipeline instead of the integrated pipeline in web.config. If the classic configuration is not already present in your web.config, you need to add it. See the web.config section below to see what to add.

These are the supported startup arguments:

(none) or -start

Starts the host process for the current Wisej application: where the process is located.

-stop

Stops the process for the current Wisej application

-p:{port} or -port:{port}

Changes the port. The default is 8080.

-d:{domain name} or -domain:{domain name}

Limits the domain: i.e. * = all, or localhost to accept local connections only. The default is *.

-i or -install

Installs Wisej.HostService as a Windows service for the current Wisej application.

-u or -uninstall

Uninstalls Wisej.HostService from the Windows services.

-n:{name} or -name:{name}

Changes the name of the service, otherwise Wisej sets the name to β€œWisej.HostService: β€œ + {Name of Wisej Application Folder}

Listening on port 80 may be restricted by the OS unless the process is started as Administrator.

Service

Register the executable to run as a service:

>Wisej.HostService -i -p:8181

You can start the same service multiple times listening on different ports.

>Wisej.HostService -i -p:8181
>Wisej.HostService -i -p:8182
>Wisej.HostService -i -p:8183

Used in conjunction with a load balancer like NGINX, you can have multiple processes of the same application handle their share of the sessions.

Process

Run Wisej.HostService.exe as any other process. You can configure Windows to start the process at startup or use Windows Task Scheduler or any other means to start the process.

>Wisej.HostService -d:localhost

Starts the process listening for connections to localhost on port 8080 (the default).

Web.Config Classic

If your web.config file doesn't include the <system.web> section (classic pipeline), add it as shown in the example below. All it needs is the definition of the Wisej httpModule. under <system.web> and to turn the validation of the integrated mode in <system.webServer>, otherwise IIS will throw in an error.

<configuration>
...
  <system.web>
    <compilation debug="false" />
    <httpRuntime targetFramework="4.8" maxRequestLength="1048576"/>
    <httpModules>
      <add name="Wisej" type="Wisej.Core.HttpModule, Wisej.Framework"/>
    </httpModules>
  </system.web>
...
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
...

Once the web.config file includes these settings it can be used with IIS, self hosting, standalone, and Ultidev/Cassini deployments.

Last updated