Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 在Kestrel上运行应用程序时,用户标识为空属性_Asp.net Core_Iis_Active Directory_Windows Authentication_Kestrel - Fatal编程技术网

Asp.net core 在Kestrel上运行应用程序时,用户标识为空属性

Asp.net core 在Kestrel上运行应用程序时,用户标识为空属性,asp.net-core,iis,active-directory,windows-authentication,kestrel,Asp.net Core,Iis,Active Directory,Windows Authentication,Kestrel,在使用Active Directory域标识进行windows身份验证期间,我遇到两种情况: 当我用IIS运行我的应用程序时,我得到了一个充满信息的对象 当我用Kestrel运行我的应用程序时,我得到的对象ClaimsPrincipal没有任何关于用户信息的信息 有什么问题吗 我的配置服务: public void ConfigureServices(IServiceCollection services) { servic

在使用Active Directory域标识进行windows身份验证期间,我遇到两种情况:

  • 当我用IIS运行我的应用程序时,我得到了一个充满信息的对象

  • 当我用Kestrel运行我的应用程序时,我得到的对象ClaimsPrincipal没有任何关于用户信息的信息

  • 有什么问题吗

    我的配置服务:

    public void ConfigureServices(IServiceCollection services)
            {
                
                services.AddDbContext<ApplicationContext>(options =>
                    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
    
                services.AddIdentity<IdentityUser, IdentityRole>().AddRoleManager<RoleManager<IdentityRole>>()
                    .AddRoles<IdentityRole>()
                    .AddEntityFrameworkStores<ApplicationContext>();
    
                services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
                services.AddAuthorization();
    
                services.AddScoped<IUserManagementManager, UserManagementManager>();
                services.AddScoped<IRolesManagementManager, RolesManagementManager>();
               
            }
    
    public void配置服务(IServiceCollection服务)
    {
    services.AddDbContext(选项=>
    options.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”));
    services.AddIdentity().AddRoleManager()
    .AddRoles()
    .AddEntityFrameworkStores();
    AddAuthentication(NegotiateDefaults.AuthenticationScheme.addConfertiate();
    services.AddAuthorization();
    services.addScope();
    services.addScope();
    }
    
    配置:

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> logger)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                else
                {
                    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.UseResponseCaching();
                app.UseRouting();
    
                app.UseAuthentication();
                app.UseAuthorization();
    
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllerRoute(
                        name: "default",
                        pattern: "{controller=Authentication}/{action=Index}");
                });
            }
    
    public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境、ILogger记录器)
    {
    if(env.IsDevelopment())
    {
    app.UseDeveloperExceptionPage();
    }
    其他的
    {
    app.UseExceptionHandler(“/Home/Error”);
    //默认的HSTS值为30天。您可能希望在生产场景中更改此值,请参阅https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
    }
    app.UseHttpsRedirection();
    app.UseStaticFiles();
    app.UseResponseCaching();
    app.UseRouting();
    app.UseAuthentication();
    app.UseAuthorization();
    app.UseEndpoints(端点=>
    {
    endpoints.MapControllerRoute(
    名称:“默认”,
    模式:“{controller=Authentication}/{action=Index}”);
    });
    }
    
    您是如何在Kestrel中配置Windows身份验证的?我发现图像中IsAuthenticated的属性为false。这可能导致您无法获得有关索赔的任何信息

    您可以在Startup.ConfigureServices中使用invoke AddAuthentication和addcongregate在Kestrel中添加身份验证服务

    services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
       .AddNegotiate();
    

    有关如何在Kestrel中配置windows身份验证的更多信息,您可以参考以下链接:

    我没有提到它,但我做了。如果是这样,那么为什么您的IsAuthenticated属性为false?这是我的问题。为什么所有属性都为空?我无法重现您的问题,您应该做的是当IsAuthenticated属性为true时,所有属性是否为空。当我运行Kestrel IsAuthenticated时,也为false。只有在IIS中,IsAuthenticated才为true