.net核心Windows身份验证红est

时间:2019-12-18 18:20:41

标签: asp.net-core-3.0

我遵循了微软的指示:https://docs.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?view=aspnetcore-3.1&tabs=visual-studio ,但是将网站移到服务器上并且第一个用户进行身份验证之后,所有用户都收到相同的身份验证...

有人可以帮助我解决这个问题吗?

Startup.cs

 plugins: [
      // Generates an `index.html` file with the <script> injected.
      new HtmlWebpackPlugin(
        Object.assign(
          {},
          {
            inject: true,
            template: paths.appHtml,

            // Here I added my defined variable name aspxPrefix that is located in my template to be replaced - <%= htmlWebpackPlugin.options.aspxPrefix %>

            aspxPrefix: '<%@ Page language="c#" CodeBehind="index_fw2.aspx.cs" AutoEventWireup="false" Inherits="IMod.Web.V2.Index" %>',

           // Then added the location and name I wanted the modified file to have here - in this case, I want it located in the build folder and renamed with .aspx

          filename: paths.appBuild+'/index.aspx'
          },

public void ConfigureServices(IServiceCollection services)
    {
        var tokenConfigurations = new TokenConfigurations();
        var signingConfigurations = new SigningConfigurations();

        services.addHttpService();

        services.AddSingleton<ValidateAuthentication>();

        services.AddHttpClient<ClientApiToken>(client => {
            client.BaseAddress = new Uri(Configuration["ApiURIs:TokenApi"]);
        });
        services.addUsuarioService(Configuration, tokenConfigurations, signingConfigurations);
        services.AddIdentityCore<ApplicationUser>()
            .AddEntityFrameworkStores<ApplicationDbContext>();
        services.AddControllersWithViews();
        services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
        .AddNegotiate();
    }
        app.UseMiddleware<ValidateAuthentication>();
        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseRouting();

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

Program.cs

internal class ValidateAuthentication : IMiddleware
{
    public async Task InvokeAsync(HttpContext context, RequestDelegate next)
    {
        if (context.User.Identity.IsAuthenticated)
            await next(context);
        else
            await context.ChallengeAsync();
    }
}

Apache Config:

public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
}

0 个答案:

没有答案