i am trying to run a .Net6 Entity Framework API on my raspberrypi.
After following the Microsoft Docs and running the application, i cannot access swaggerui or API.
There are no errors poping up in console when i try to access the page via http://localhost:5000/
The webbrowser just returns a 401 Error.
Following Code:
Program.cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<programContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("Context") ?? throw new InvalidOperationException("Connection string 'Context' not found.")));
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseHttpsRedirection();
}
app.UseSwagger();
app.UseSwaggerUI();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
appsettings.json:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"programApiContext": "Server=(localdb)\mssqllocaldb;Database=programApi.Data;Trusted_Connection=True;MultipleActiveResultSets=true",
"programContext": "Server=(localdb)\mssqllocaldb;Database=programApi.Data;Trusted_Connection=True;MultipleActiveResultSets=true"
}
dotnet -info:
.NET SDK (gemäß "global.json"):
Version: 6.0.301
Commit: 43f9b18481
Laufzeitumgebung:
OS Name: debian
OS Version: 11
OS Platform: Linux
RID: debian.11-arm64
Base Path: /opt/dotnet/sdk/6.0.301/
Host (useful for support):
Version: 6.0.6
Commit: 7cca709db2
.NET SDKs installed:
6.0.301 [/opt/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.6 [/opt/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.6 [/opt/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
nginx-site config:
server {
listen 80;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
2
Answers
After launch your application follow bellow link to get swagger
Check your launchSettings.json
To retrieve the Swagger document you need to use its full path. From the Get started with Swashbuckle and ASP.NET Core docs:
You have to use extra code to display the UI at the root