ASP.NET Core Web API Authentication Method Switch Between JWT & Window Authentication

I build an app that used JWT for authentication, I need to add windows authentication as other method, to switch between both, as customer need.

I have created a middleware to do this job, It worked probably while development. though, when I publish the release & deploy it in IIS I got error this

The Negotiate Authentication handler cannot be used on a server that directly supports Windows Authentication. Enable Windows Authentication for the server and the Negotiate Authentication handler will defer to it.

this is JWT Authentication code. Note: every thing configured to work in JWT Auth.

// Dependency Injection.cs
string? authScheme = configuration["AuthenticationScheme"];
if (authScheme) {
               JwtTokenConfig? jwtTokenConfig = configuration.GetSection("jwtTokenConfig").Get<JwtTokenConfig>();
               services.AddSingleton(jwtTokenConfig);
               services.AddAuthentication(x =>
               {
                   x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                   x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
               }).AddJwtBearer(x =>
               {
              // options
               }).AddNegotiate();

               // JWT Authentication (Anonymous)
               services.AddScoped<IAuthManager, JwtAuthManager>();
               services.AddHostedService(sp => new JwtRefreshTokenCache(new JwtAuthManager(jwtTokenConfig)));
               // Add CORS services
               services.AddCors(options =>
               {options.AddPolicy("AllowSpecificOrigin",
                       builder => builder.WithOrigins("http://localhost:4200")
                                         .AllowAnyHeader()
                                         .AllowAnyMethod()
                                         .AllowCredentials());
               });
           }
}

this is the middleware code

    public class AuthMiddleware
    {
        private readonly RequestDelegate _next;
        private readonly IConfiguration _configuration;
        public AuthMiddleware(RequestDelegate next, IConfiguration configuration)
        {
            _next = next;
            _configuration = configuration;
        }

        public async Task InvokeAsync(HttpContext context)
        {
            var authScheme = _configuration["AuthenticationScheme"];
            var publicRoutes = new List<string>
            { "/",
 "/api/v1",
 "/api/v1/Account/Login" };
            if (publicRoutes.Any(route => context.Request.Path.StartsWithSegments(route, StringComparison.OrdinalIgnoreCase)))
            { await _next(context); return; }
            AuthenticateResult result = null;
            if (authScheme == "Windows") { result = await context.AuthenticateAsync(NegotiateDefaults.AuthenticationScheme); }
            else if (authScheme == "JwtBearer")
            { result = await context.AuthenticateAsync(JwtBearerDefaults.AuthenticationScheme); }
            if (result != null && result.Succeeded)
            { context.User = result.Principal; await _next(context); }
            else { await context.ChallengeAsync(); }
        }
    }

Base Controller to inherit the Auth method to rest of controllers.

    // [Authorize(AuthenticationSchemes = IISDefaults.AuthenticationScheme)]
    [Authorize]
    public class BaseController<T> : Controller

Program.cs

app.UseAuthentication();
app.UseMiddleware<AuthMiddleware>();
app.UseAuthorization();

I’ve tried changing the IIS settings, Application Pool Identity, changing windows authentication providers.
I tried to implement it without Negotiate.

if I turn Windows Authentication off in IIS, the web will stop completely with 404 error, if I turned windows authentication on, it ask me to login through it, and even if I did nothing happened.

the app is completely off, no page is shown even login page, because the error in program.cs so nothing will work at all.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật