Set up local hosting

When developing websites, you often need to quickly build and test code changes made to the project. For this reason, it’s useful to have the site hosted locally on your development machine. ASP.NET Core is very flexible in this aspect as it offers multiple hosting options for its supported platforms.

See the following sections for a breakdown of hosting options available on each platform supported by Xperience:

Windows platforms

Kestrel

The Kestrel web server is the recommended hosting option. It is cross-platform, usually offers better performance, and will have the strongest .NET support in the future.

You can launch all projects locally via the dotnet run command: 



cd <project_directory>
dotnet run

This launches the application on localhost using an empty port randomly assigned during the installation process. You can change the assigned defaults via the project’s launchSettings.json file.

IIS Express

IIS Express is a lightweight, self-contained version of IIS optimized for developers. IIS Express makes it easy to use the most current version of IIS to develop and test websites. It has all the core capabilities of IIS 7 and above as well as additional features designed to ease website development including:

  • It doesn’t run as a service or require administrator user rights to perform most tasks.
  • IIS Express works well with ASP.NET Core and PHP applications.
  • Multiple users of IIS Express can work independently on the same computer.

To host the installed project using IIS Express:

  1. Open the installed project in Visual Studio.
  2. Right-click the project file and select Properties.
  3. Under Debug:
    • Set Launch to IIS Express.
      Configure IIS hosting for the application
  4. Save the changes and run the project using the profile you configured (IIS Express in this example).

Alternatively, you can use the project’s launchSettings.json file to configure launch profiles.

You can now launch the project using IIS Express.

IIS

ASP.NET Core also supports hosting using Internet Information Services (IIS). You can host applications either in-process (through the wpw3.exe worker) or out-of-process (using reverse proxy with Kestrel).

See the official Microsoft documentation Host ASP.NET Core on Windows with IIS for the required configuration and set up. Make sure that you have ASP.NET Core 6.0 Runtime - Windows Hosting Bundle installed.

Linux distributions

Kestrel

The Kestrel web server is supported by default by all ASP.NET Core web applications.

You can launch all projects locally via the dotnet run command: 



$ cd <project_directory>
$ dotnet run

Which launches the application on localhost using an empty port randomly assigned during the installation process.

Ngnix and Apache

ASP.NET Core also supports hosting using Apache and Nginx.

See the official Microsoft documentation for

to learn how to configure hosting using these services.

Hosting configuration notes

Enable static web assets in non-Development local environments

The Xperience application must have static web assets enabled to correctly load script files and other resources. When running Xperience locally (e.g., using the built-in Visual Studio IIS Express server), static web assets are enabled by default in the Development environment. However, if you are using a different environment, e.g., by setting ASPNETCORE_ENVIRONMENT to a different value in the Properties/launchSettings.json file, you need to enable static web assets – call UseStaticWebAssets on WebApplicationBuilder in Program.cs.

Program.cs


using Kentico.Web.Mvc;

var builder = WebApplication.CreateBuilder(args);  

...

builder.Services.AddKentico(features =>
{
    ...
});

...

// Enables static web assets
builder.WebHost.UseStaticWebAssets();