Asp.net core NetCore API在Nginx上托管时给出错误代码500
我使用.net core 5.0构建简单的API来获取用户名,该用户名在本地运行良好,但在nginx/1.14.1服务器上发布时,响应状态代码为500 Internal server Error 这是我的初创公司Asp.net core NetCore API在Nginx上托管时给出错误代码500,asp.net-core,nginx,Asp.net Core,Nginx,我使用.net core 5.0构建简单的API来获取用户名,该用户名在本地运行良好,但在nginx/1.14.1服务器上发布时,响应状态代码为500 Internal server Error 这是我的初创公司 public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddControllers();
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddHttpContextAccessor();
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
services.AddScoped<ValidateAuthentication>();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseAuthentication();
app.UseMiddleware<ValidateAuthentication>();
.........
}
}
您所描述的更像是nginx的错误配置,而不是程序错误。您的代码在这里没有帮助,您最好发布nginx
server
block和nginx错误日志中的相应行。
[ApiController]
public class UserController : ControllerBase
{
private readonly IHttpContextAccessor _httpContextAccessor;
public UserController(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
[HttpGet]
public string GetUserName()
{
//_logger.LogInformation("Receive UserController Request");
string userName = _httpContextAccessor.HttpContext.User.Identity.Name;
return userName;
}
}