I've created a simple ASP.NET Core Web Application (as an Api), and everything is working fine on Windows. I am trying to run it through a reverse proxy on Nginx and the app fails with an authentication error:
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://ite.photosite.shop/Ite/Status
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://ite.photosite.shop/Ite/Status
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method IteWebCore.Controllers.IteController.Status (IteWebCore) with arguments ((null)) - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method IteWebCore.Controllers.IteController.Status (IteWebCore) with arguments ((null)) - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.ForbidResult[1]
Executing ForbidResult with authentication schemes ().
info: Microsoft.AspNetCore.Mvc.ForbidResult[1]
Executing ForbidResult with authentication schemes ().
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action IteWebCore.Controllers.IteController.Status (IteWebCore) in 48.0151ms
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action IteWebCore.Controllers.IteController.Status (IteWebCore) in 48.0151ms
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLDAN95N3T3V", Request id "0HLDAN95N3T3V:00000001": An unhandled exception was thrown by the application.
System.InvalidOperationException: No authenticationScheme was specified, and there was no DefaultForbidScheme found.
at Microsoft.AspNetCore.Authentication.AuthenticationService.<ForbidAsync>d__12.MoveNext()
It works fine directly going through Kestral on port 5000 (it looks like this):
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://localhost:5000/Ite/Status
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method IteWebCore.Controllers.IteController.Status (IteWebCore) with arguments ((null)) - ModelState is Valid
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://localhost:5000/Ite/Status
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method IteWebCore.Controllers.IteController.Status (IteWebCore) with arguments ((null)) - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.Internal.ContentResultExecutor[1]
Executing ContentResult with HTTP Response ContentType of text/html
info: Microsoft.AspNetCore.Mvc.Internal.ContentResultExecutor[1]
Executing ContentResult with HTTP Response ContentType of text/html
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action IteWebCore.Controllers.IteController.Status (IteWebCore) in 10.979ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 12.1335ms 200 text/html
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action IteWebCore.Controllers.IteController.Status (IteWebCore) in 10.979ms
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 12.1335ms 200 text/html
I've tried all the suggestions about various ways of setting up the authentication service, the current Startup Class looks like:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddAuthentication(Microsoft.AspNetCore.Server.HttpSys.HttpSysDefaults.AuthenticationScheme);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute("default", "{controller=Ite}/{action=Execute}");
});
}
}
The current nginx conf looks like:
server {
listen 80;
server_name ite.photosite.shop;
access_log /var/log/nginx/ite-photosite-access.log;
error_log /var/log/nginx/ite-photosite-error.log notice;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
}
}
Which I took from the this instructions on deploying on linux. Even though I am currently doing no authentication, I also added (and removed, and tried every combination of):
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
In the configure section.
Every time I get the same error.
Edit - added startup class