2017-08-25 277 views
0

当与运行角:DOTNET运行 - 角 - Windows身份验证 - 未通过身份验证

NG服务--proxy-配置proxy.config.js

和.NET的核心有:

DOTNET运行

Windows身份验证内华达州呃认证用户。

但是,当从Visual Studio F5用户运行应用程序进行身份验证时,(相同的端口和所有内容)。

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手表运行不适用于Windows身份验证,但Visual Studio F5呢?

更新

我曾尝试加入“weblistener”,而不是在项目属性中启用身份验证。加入weblistener后,我能够用dotnet的运行来验证,但我再也不能开始使用VS F5出于某种原因调试...

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

回答

0

Windows身份验证不DOTNET CLI支持。

我不知道如果你在IIS中发布你的应用程序(没有httpsys或weblistener)(不支持在IIS中),你应该如何在本地开发。

我目前正在使用IIS Express,这是一个痛苦的屁股。

Source

0

如果不久:dotnet run启动应用程序,而无需使用IIS作为反向代理等所有IIS设置都将被忽略


你,你只有当您运行从Visual Studio应用程序iisSettings部分用于launchSettings.json

这个json文件保存了与每个调试配置文件相关的项目特定设置,Visual Studio被配置为用来启动应用程序,包括应该使用的任何环境变量。

当您执行dotnet run命令时,the Web Server (Kestrel by default) starts and hosts the app

当您从VS启动应用程序时,IIS Express实例也被配置为您的应用程序的反向代理。这是启用Windows身份验证。

查看IIS Publishing了解如何配置IIS + ASP.NET Core应用程序的详细信息。如果你不使用HTTPSYSWeblistener,(weblistener在2.0 httpsys更换?)

没有窗户,没有Windows身份验证

+0

据我了解,我必须使用WebListener或IIS +红隼对于Windows身份验证。我试过weblistener但是不会允许我使用iis进行调试?另外我无法找到dotnet run + iis的解决方案。你知道为什么我不能使用weblistener进行调试,并且你有一个适用于iis和dotnet的解决方案吗? – Reft

+0

@Reft是,可以为IIS Core或WebListener托管的ASP.NET Core应用程序配置Windows身份验证。而WebListener不能与IIS或IIS Express一起使用,因为它与ASP.NET核心模块不兼容。查看[在ASP.NET Core中配置Windows身份验证](https://docs.microsoft.com/zh-cn/aspnet/core/security/authentication/windowsauth) - 您可以配置IIS站点,而不是使用VS + IIS Express – Set

+0

对不起,但这并没有帮助我。一旦应用程序部署完毕,Windows身份验证就会像应该那样工作。问题是当我在当地发展。该应用程序托管在iis,所以我想开发使用iis express和dotnet cli。我不想在localhost中使用httpsys。使用dotnet cli阻止我使用iis express?我是否被迫使用visual studio而不是dotnet watch run? – Reft

相关问题