Elsa Server + Studio (WASM)
In this topic, we will create an ASP.NET Core application that acts as both an Elsa Server and an Elsa Studio.
Instead of running Elsa Server and Elsa Studio as separate ASP.NET Core applications, you can also setup an ASP.NET Core application that hosts both the workflow server and the UI. The UI will still make HTTP calls to the backend as if they were hosted separately, but the difference is that they are now served from the same application and therefore deployable as a single unit.
For Elsa Studio, we will setup the Blazor parts using Blazor WebAssembly, which static files will be served from the ASP.NET Core host application.
This walkthrough requires the .NET 10 SDK and targets Elsa 3.8.0. The server must receive a real identity signing key and deployment-owned users/applications before startup. Stable 3.8.0 does not provide production-usable default admin credentials.
Create Solution
In this chapter, we will scaffold a new solution and two projects:
The Host
The Client
The host will host both Elsa Server and the Blazor WebAssembly application representing Elsa Studio.
Run the following commands to create a solution with two projects:
# Create a new solution
dotnet new sln -n ElsaServerAndStudio
# Create the host project
dotnet new web -n "ElsaServer" --framework net10.0
# Add the host project to the solution
dotnet sln add ElsaServer/ElsaServer.csproj
# Create the client project
dotnet new blazorwasm -n "ElsaStudio" --framework net10.0
# Add the client project to the solution
dotnet sln add ElsaStudio/ElsaStudio.csproj
# Navigate to the directory where the host project is located
cd ElsaServer
# Add a reference to the client project
dotnet add reference ../ElsaStudio/ElsaStudio.csprojSetup Host
In this chapter, we will setup the host, which will host both the Elsa Server engine as well as the webassembly files for serving the Elsa Studio client assets to the browser.
Add Packages
Add the following packages:
Update Program.cs
Open the Program.cs file in your project and replace its contents with the code provided below. This code does a lot of things like setting up database connections, enabling user authentication, and preparing the server to handle workflows.
Program.cs
The example stores identity data in the same SQLite database as the workflow data and creates an administrator on first startup. Set Identity:Bootstrap:UserName and Identity:Bootstrap:Password (or their double-underscore environment-variable forms) through deployment-owned configuration. Set Identity:Tokens:SigningKey (or Identity__Tokens__SigningKey) to a random printable-ASCII value of at least 32 characters. The C# and Python engines are host-code execution and are disabled by default; enable them only for trusted authors and grant the matching exec:csharp-expressions or exec:python-expressions permission. See Upgrade to Elsa 3.8.0 for the full security and module checklist. 3. Update appsettings.json
4. Create _Host.cshtml
Setup Client
Next, we will modify the client project.
Add Elsa Studio Packages
Navigate to the root directory of the client project and add the following Elsa Studio packages:
Before changing Program.cs, add this property inside a PropertyGroup in the client .csproj. Studio selects its culture during startup, so the WebAssembly application must load the required globalization data:
Modify Program.cs
Open
Program.csand replace its existing content with the code provided below:Program.cs
Configure Client Authentication and Localization
The hosted page still supplies the backend API URL through
window.getClientConfig, but the client can usewwwroot/appsettings.jsonto select the Studio authentication provider and localization settings:The sample selects
ElsaIdentityso it can use the server bootstrap administrator. TheOpenIdConnectsection is inactive until you changeProvidertoOpenIdConnectand replace its placeholders with your identity-provider settings.AuthenticationScopesare used during Studio sign-in.BackendApiScopesare used when Studio requests bearer tokens for Elsa Server API calls.Because this client is Blazor WebAssembly, register
{studio-url}/authentication/login-callbackas the redirect URI and{studio-url}/authentication/logout-callbackas the logout callback URI. Studio initiates logout at{studio-url}/authentication/logout.Modify MainLayout.razor
Update
Layout/MainLayout.razorwith the following code listing:MainLayout.razor
Launch the Application
To see your application in action, navigate back to the root directory containing the host project:
Then execute the following command:
Your application is now accessible at https://localhost:5001.
Sign in with a user configured by the server's identity provider. Stable 3.8.0 no longer supplies a hard-coded admin/password login.
Source Code
The source code for this chapter can be found here
Last updated