dotnet运行-角度-Windows身份验证-未通过身份验证 [英] dotnet run - angular - windows authentication - not authenticated

查看:65
本文介绍了dotnet运行-角度-Windows身份验证-未通过身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当与以下设备成角度运行时:

When running angular with:

ng serve --proxy-config proxy.config.js

ng serve --proxy-config proxy.config.js

和.net核心,其中:

and .net core with:

dotnet运行

dotnet run

Windows身份验证从不对用户进行身份验证.

windows authentication never authenticate user.

但是,从Visual Studio F5运行应用程序时,需要对用户进行身份验证(相同的端口和所有端口).

However when running the application from Visual Studio F5 user is authenticated, (same port and everything).

proxy.config.js

const Agent = require('agentkeepalive');

module.exports = {
        '/api': {
            target: 'http://localhost:5000',
            secure: false,
            agent: new Agent({
                maxSockets: 100,
                keepAlive: true,
                maxFreeSockets: 10,
                keepAliveMsecs: 100000,
                timeout: 6000000,
                keepAliveTimeout: 90000
            }),
            onProxyRes: proxyRes => {
                let key = 'www-authenticate';
                proxyRes.headers[key] = proxyRes.headers[key] &&
                    proxyRes.headers[key].split(',');
            }
        }
};

iisSettings

iisSettings": {
    "windowsAuthentication": true,
    "anonymousAuthentication": false,
    "iisExpress": {
      "applicationUrl": "http://localhost:5000/",
      "sslPort": 0
    }
  }

Startup.cs

public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(IISDefaults.AuthenticationScheme);

            services.AddMvc(config =>
            {
                var policy = new AuthorizationPolicyBuilder()
                    .RequireAuthenticatedUser()
                    .Build();
                config.Filters.Add(new AuthorizeFilter(policy));
            });

            services.AddMvc();
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.Use(async (context, next) =>
            {
                await next();
                if (context.Response.StatusCode == 404 &&
                    !Path.HasExtension(context.Request.Path.Value) &&
                    !context.Request.Path.Value.StartsWith("/api/"))
                {
                    context.Request.Path = "/index.html";
                    await next();
                }
            });

            app.UseMvcWithDefaultRoute();

            app.UseDefaultFiles();

            app.UseStaticFiles();
        }
    }

为什么dotnet运行和dotnet watch run不适用于Windows身份验证,但Visual Studio F5可以运行?

Why is that dotnet run and dotnet watch run doesn't work with windows authentication but Visual Studio F5 does?

更新

我尝试添加"weblistener",而不是在项目属性中启用身份验证.添加weblistener之后,我能够使用dotnet run进行身份验证,但是由于某些原因,我不再能够使用VS F5开始调试...

I have tried adding "weblistener" instead of enabling authentication in project properties. After adding weblistener I was able to authenticate using dotnet run but I could no longer start debugging using VS F5 for some reason...

.UseHttpSys(options =>
            {
                options.Authentication.Schemes = AuthenticationSchemes.NTLM;
                options.Authentication.AllowAnonymous = false;
            })

推荐答案

如果您不使用

Windows authentication is not supported in dotnet cli if you're not using HTTPSYS or Weblistener, (weblistener replaced with httpsys in 2.0?)

没有Windows,没有Windows身份验证.

No Windows, no Windows auth.

如果您要在IIS中发布应用程序(不使用httpsys或weblistener)(在IIS中不支持),则我不确定如何在本地进行开发.

I'm not sure how you're supposed to develop locally if you're publishing your app in IIS, (without httpsys or weblistener), (not supported in IIS).

我当前正在使用IIS Express,这很麻烦.

I'm currently using IIS Express which is a pain in the butt.

来源

这篇关于dotnet运行-角度-Windows身份验证-未通过身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆