English
Deploy an ASP.NET application
Suppose you have an ASP.NET Core application that you want to run under the domain domain.com. The application runs on Kestrel at port 3000 and is managed by a Systemd Service, while the website on FlashPanel forwards requests for the domain to port 3000.
Prerequisites
- Server connected to FlashPanel
- Domain DNS pointed to the server's IP
Step 1: Install the .NET SDK
Go to the server management page, click the Apps menu, select the Not Installed tab, find ASP.NET Core, then click Install. Choose the Version that matches your project's .NET version (for example, choose 8.0 for a project targeting net8.0). See Applications for details.
Step 2: Create a Website
- Go to the server management page, click the Sites menu in the sidebar, then click the New Site button
- Enter the Domain Name (e.g.,
domain.com) - Enter the Proxy Port: the port your application will listen on, for example
3000 - Click Create Site
TIP
If you enable Website Isolation, the website runs as its own Linux user. In that case, replace flashpanel in the paths below with the website's isolation username.
Step 3: Upload the Source Code
Choose one of the following:
- From Git (recommended): on the site management page, click the Install Source Code menu and install your repository. See Source Code Installation.
- Upload it yourself: open File Manager on the website's overview page and upload your code to the website directory. See File Manager.
The source code lives in /home/flashpanel/domain.com.
Step 4: Build and Publish
Open Terminal on the website's overview page (the terminal logs in as the user that owns the website and opens the website directory), then run:
bash
cd /home/flashpanel/domain.com
# Update the database (only when using Entity Framework Core migrations)
dotnet ef database update
# Build and publish the Release version to the publish directory
dotnet publish -c Release -o publishAfter this command, the main file is publish/<ProjectName>.dll, for example publish/domain_com.dll.
TIP
dotnet ef database update is only needed if your application uses Entity Framework Core and the dotnet-ef tool is installed (dotnet tool install --global dotnet-ef). Skip it if your application does not use database migrations.
Step 5: Create a Service for the Application
Use the Systemd Service management feature to run the application in the background and restart it automatically:
- Go to the server management page, click the Service menu, then click Create Service
- Enter a Name, for example
domain_com(short, without special characters) - Replace the content in the editor with the following:
ini
[Unit]
Description=ASP.NET - domain.com
[Service]
WorkingDirectory=/home/flashpanel/domain.com/publish
ExecStart=/usr/bin/dotnet /home/flashpanel/domain.com/publish/domain_com.dll --urls "http://127.0.0.1:3000"
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=domain_com
User=flashpanel
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
StandardOutput=append:/var/log/services/domain_com.log
StandardError=append:/var/log/services/domain_com-error.log
[Install]
WantedBy=multi-user.target- Keep Boot with the system selected so the service starts when the server reboots
- Click Create Service. The service is created and started right away
WARNING
- Replace
3000with the website's Proxy Port.127.0.0.1makes the application accept requests only through the website, without exposing the port to the Internet - Replace
domain.comwith your website's domain anddomain_com.dllwith your project's dll file name Useris the user that owns the website (do not useroot)- Linux file names are case-sensitive. With
ASPNETCORE_ENVIRONMENT=Production, the application readsappsettings.Production.json, notappsettings.production.json - Environment variable names do not support the colon (
:). Use a double underscore (__) instead; for example, the keyConnectionStrings:DefaultConnectionis declared as:iniEnvironment=ConnectionStrings__DefaultConnection={Connection String}
Step 6: Install SSL
On the site management page, click the SSL menu and install a certificate for the domain. See SSL.
Verify the Result
- On the Service page, the
domain_comservice shows as active - Visit
https://domain.comand check that your application responds correctly
Updating the Application
- Update the source code (click Deploy Now in the Deployments menu if it was installed from Git, or upload the new version with File Manager)
- Open the website's Terminal and run
dotnet publish -c Release -o publishagain - On the Service page, click the Restart button of the
domain_comservice
TIP
If the source code was installed from Git, you can add dotnet publish -c Release -o publish to the Deployment Script so you do not have to run step 2 by hand. The Deployment Script runs as the user that owns the website, so it cannot restart a Systemd Service; you still need to click Restart on the Service page.
Troubleshooting
Application Won't Start
- On the Service page, click View Error Log for the
domain_comservice - Run the application manually in the website directory to see the error:
dotnet publish/domain_com.dll --urls "http://127.0.0.1:3000" - Check that the dll path in
ExecStartis correct
502 Bad Gateway
- Check that the service is running on the Service page
- Make sure the port in
--urlsmatches the website's Proxy Port - See also 502 Bad Gateway
You must install or update .NET to run this application
The installed .NET version does not match the version your project targets. Run dotnet --list-runtimes to see the installed versions, then install the right version on the Apps page.