I just deployed my ASP.NET Core web application on my raspberry pi 4b which works just fine when I start it manually via the terminal. As I need it to start right after the start, I thought of Autostart -> so I found some methods to do so (I already tried lxde, crontab and rc.local), every time I start my raspberry, the application starts just fine but my images, which are stored in the wwwroot folder are missing and I get an error 404. I also tried adding sudo.
When I tried to run the application via bash (so I could see the logs), I encountered following message:
User profile is available. Using '/home/user/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
My Program.cs file looks like this:
using GaragenSteuerung.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Services.AddSingleton<IRelayService, RelayService>();
builder.Services.AddRazorPages();
var app = builder.Build();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapRazorPages();
app.Run();
I tried those several autostart methods as well as different publishing methods (one file, folder), and bootstrap did also not work when I stored it locally
You can create a
.servicefile where ExecStart points to the dotnet command and then your .dll.Copy the
.servicefile to /etc/systemd/system/ then run:Then the
.dll willnow be run on system boot. Enjoy! Or, to see a worked through example, keep reading on.For more details, you can check this blog: Creating an Autostart .NET 6 Service on a Raspberry Pi