.net dotnet运行-角度-windows身份验证-未经身份验证
当以以下方式运行时: ng serve—代理配置proxy.config.js 和.net内核,具有: 网络运行 windows身份验证从不对用户进行身份验证 但是,当从Visual Studio F5运行应用程序时,用户已通过身份验证(相同的端口和所有内容) proxy.config.js.net dotnet运行-角度-windows身份验证-未经身份验证,.net,angular,asp.net-core,windows-authentication,.net,Angular,Asp.net Core,Windows Authentication,当以以下方式运行时: ng serve—代理配置proxy.config.js 和.net内核,具有: 网络运行 windows身份验证从不对用户进行身份验证 但是,当从Visual Studio F5运行应用程序时,用户已通过身份验证(相同的端口和所有内容) proxy.config.js const Agent = require('agentkeepalive'); module.exports = { '/api': { target: 'htt
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": {
"windowsAuthentication": true,
"anonymousAuthentication": false,
"iisExpress": {
"applicationUrl": "http://localhost:5000/",
"sslPort": 0
}
}
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();
}
}
iisSettings
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": {
"windowsAuthentication": true,
"anonymousAuthentication": false,
"iisExpress": {
"applicationUrl": "http://localhost:5000/",
"sslPort": 0
}
}
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();
}
}
Startup.cs
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": {
"windowsAuthentication": true,
"anonymousAuthentication": false,
"iisExpress": {
"applicationUrl": "http://localhost:5000/",
"sslPort": 0
}
}
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监视运行不适用于windows身份验证,而Visual Studio F5适用于此
更新
我尝试添加“weblistener”,而不是在项目属性中启用身份验证。添加weblistener后,我可以使用dotnet run进行身份验证,但由于某些原因,我无法再使用VS F5开始调试
.UseHttpSys(options =>
{
options.Authentication.Schemes = AuthenticationSchemes.NTLM;
options.Authentication.AllowAnonymous = false;
})
如果很快:
dotnet run
在不使用IIS作为反向代理的情况下启动应用程序,因此将忽略所有IIS设置
只有当您从Visual Studio运行应用程序时,才会使用您的
launchSettings.json
部分,其中包含iisSettings
此json文件保存与每个调试配置文件关联的项目特定设置,Visual Studio配置为用于启动应用程序,包括应使用的任何环境变量
执行dotnet run
命令时
从VS启动应用程序时,IIS Express实例也会配置为应用程序的反向代理。这就是启用Windows身份验证
查看有关如何配置IIS+ASP.NET核心应用程序的详细信息。如果很快:
dotnet run
在不使用IIS作为反向代理的情况下启动应用程序,因此会忽略所有IIS设置
只有当您从Visual Studio运行应用程序时,才会使用您的
launchSettings.json
部分,其中包含iisSettings
此json文件保存与每个调试配置文件关联的项目特定设置,Visual Studio配置为用于启动应用程序,包括应使用的任何环境变量
执行dotnet run
命令时
从VS启动应用程序时,IIS Express实例也会配置为应用程序的反向代理。这就是启用Windows身份验证
查看有关如何配置IIS+ASP.NET核心应用程序的详细信息。如果您未使用或(weblistener在2.0中被httpsys替换),则dotnet cli中不支持Windows身份验证 没有Windows,没有Windows身份验证 我不确定如果你在IIS中发布你的应用(没有httpsys或weblistener)(IIS不支持),你应该如何在本地开发 我目前正在使用IIS Express,这是一个令人头痛的问题
如果您没有使用或(weblistener在2.0中被httpsys替换),则dotnet cli中不支持Windows身份验证 没有Windows,没有Windows身份验证 我不确定如果你在IIS中发布你的应用(没有httpsys或weblistener)(IIS不支持),你应该如何在本地开发 我目前正在使用IIS Express,这是一个令人头痛的问题
我发现大卫·福勒对类似问题的回应。 网址:
通过这些更改,我可以在VisualStudio和从dotnet运行命令中运行。我发现David Fowler对类似问题的响应。 网址:
通过这些更改,我可以在Visual Studio和从dotnet运行命令中运行。据我所知,我必须使用WebListener或IIS+Kestrel进行windows身份验证。我尝试过weblistener,但这不允许我使用iis进行调试?我也找不到dotnet run+iis的解决方案。您知道为什么我不能使用weblistener进行调试吗?您是否有一个同时适用于iis和dotnet运行的解决方案?@Reft是的,可以为使用iis或weblistener托管的ASP.NET核心应用配置Windows身份验证。WebListener不能与IIS或IIS Express一起使用,因为它与ASP.NET核心模块不兼容。查看-您可以配置IIS站点,而不是使用VS+IIS Express抱歉,但这对我没有帮助。部署应用程序后,windows身份验证将正常工作。问题是当我在本地开发时。该应用程序托管在iis中,因此我希望使用iis express和dotnet cli进行开发。我不想在localhost中使用httpsys。使用dotnet cli会阻止我使用iis express吗?我是被迫使用visual studio而不是dotnet watch run吗?@Reft您找到解决方案了吗?我也遇到了同样的困境。@BurningHippo我在整个互联网上搜索了答案,但还没有找到答案。。请让我知道,如果你找到了解决这个问题的办法。目前我使用的是iis express而不是dotnet cli,据我所知,这很可怕,我必须使用WebListener或iis+Kestrel进行windows身份验证。我尝试过weblistener,但这不允许我使用iis进行调试?我也找不到dotnet run+iis的解决方案。您知道为什么我不能使用weblistener进行调试吗?您是否有一个同时适用于iis和dotnet运行的解决方案?@Reft是的,可以为使用iis或weblistener托管的ASP.NET核心应用配置Windows身份验证。WebListener不能与IIS或IIS Express一起使用,因为它与ASP.NET核心模块不兼容。查看-您可以配置IIS站点,而不是使用VS+IIS Express抱歉,但这对我没有帮助。部署应用程序后,windows身份验证将正常工作。问题是当我在本地开发时。该应用程序托管在iis中,因此我希望使用iis express和dotnet cli进行开发。我不想在localhost中使用httpsys。使用dotnet cli会阻止我使用iis express吗?我是被迫使用visual studio而不是dotnet watch run吗?@Reft您找到解决方案了吗?“我也陷入了同样的困境。”伯宁希波我搜索了整个国际米兰