简体   繁体   English

IHttpContextAccessor.HttpContext 的 Windows 登录名是 Null .net 6

[英]windows login name by IHttpContextAccessor.HttpContext is Null .net 6

enter image description here在此处输入图像描述

enter image description here在此处输入图像描述

and add services in startup.并在启动时添加服务。 but when i make this process on core 5,this process is Done.但是当我在核心 5 上进行这个过程时,这个过程就完成了。

In .NET 6 Microsoft has removed the Startup.cs class.在 .NET 6 中,Microsoft 删除了 Startup.cs 类。 Be sure configure the services in Program.cs in .NET 6 like below:请确保在 .NET 6 中的 Program.cs 中配置服务,如下所示:

using Microsoft.AspNetCore.Authentication.Negotiate;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
   .AddNegotiate();

builder.Services.AddAuthorization(options =>
{
    // By default, all incoming requests will be authorized according to the default policy.
    options.FallbackPolicy = options.DefaultPolicy;
});
builder.Services.AddRazorPages();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM