dotnet 运行 - angular - windows 认证 - 未认证
dotnet run - angular - windows authentication - not authenticated
当运行宁angular与:
ng serve --proxy-config proxy.config.js
和 .net 核心:
dotnet run
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 运行 和 dotnet watch 运行 不适用于 windows 身份验证,但 Visual Studio F5 可以?
更新
我尝试添加 "weblistener" 而不是在项目属性中启用身份验证。添加 weblistener 后,我可以使用 dotnet 运行 进行身份验证,但由于某种原因我无法再使用 VS F5 开始调试...
.UseHttpSys(options =>
{
options.Authentication.Schemes = AuthenticationSchemes.NTLM;
options.Authentication.AllowAnonymous = false;
})
如果很快:dotnet run
在不使用 IIS 作为反向代理的情况下启动应用程序,因此您的所有 IIS 设置都将被忽略
只有当您 运行 来自 Visual Studio.
的应用程序时,才会使用您的 launchSettings.json
部分 iisSettings
This json file holds project specific settings associated with each debug profile, Visual Studio is configured to use to launch the application, including any environment variables that should be used.
当你执行dotnet run
命令时,the Web Server (Kestrel by default) starts and hosts the app。
当您从 VS 启动应用程序时,IIS Express 实例也被配置为您的应用程序的反向代理。这是启用 Windows 身份验证。
查看 IIS Publishing 了解如何配置 IIS + ASP.NET 核心应用程序的详细信息。
Windows 如果您不使用 HTTPSYS or Weblistener,dotnet cli 不支持身份验证,(weblistener 在 2.0 中被 httpssys 取代?)
无Windows,无Windows授权
如果您在 IIS 中发布您的应用程序(没有 httpssys 或 weblistener)(IIS 不支持),我不确定您应该如何在本地开发。
我目前正在使用 IIS Express,这让我很头疼。
我找到了 David Fowler 对类似问题的回应。
Url: https://github.com/aspnet/HttpSysServer/issues/425
通过这些更改,我可以在 Visual Studio 和 dotnet 运行 命令中 运行。
当运行宁angular与:
ng serve --proxy-config proxy.config.js
和 .net 核心:
dotnet run
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 运行 和 dotnet watch 运行 不适用于 windows 身份验证,但 Visual Studio F5 可以?
更新
我尝试添加 "weblistener" 而不是在项目属性中启用身份验证。添加 weblistener 后,我可以使用 dotnet 运行 进行身份验证,但由于某种原因我无法再使用 VS F5 开始调试...
.UseHttpSys(options =>
{
options.Authentication.Schemes = AuthenticationSchemes.NTLM;
options.Authentication.AllowAnonymous = false;
})
如果很快:dotnet run
在不使用 IIS 作为反向代理的情况下启动应用程序,因此您的所有 IIS 设置都将被忽略
只有当您 运行 来自 Visual Studio.
的应用程序时,才会使用您的launchSettings.json
部分 iisSettings
This json file holds project specific settings associated with each debug profile, Visual Studio is configured to use to launch the application, including any environment variables that should be used.
当你执行dotnet run
命令时,the Web Server (Kestrel by default) starts and hosts the app。
当您从 VS 启动应用程序时,IIS Express 实例也被配置为您的应用程序的反向代理。这是启用 Windows 身份验证。
查看 IIS Publishing 了解如何配置 IIS + ASP.NET 核心应用程序的详细信息。
Windows 如果您不使用 HTTPSYS or Weblistener,dotnet cli 不支持身份验证,(weblistener 在 2.0 中被 httpssys 取代?)
无Windows,无Windows授权
如果您在 IIS 中发布您的应用程序(没有 httpssys 或 weblistener)(IIS 不支持),我不确定您应该如何在本地开发。
我目前正在使用 IIS Express,这让我很头疼。
我找到了 David Fowler 对类似问题的回应。 Url: https://github.com/aspnet/HttpSysServer/issues/425
通过这些更改,我可以在 Visual Studio 和 dotnet 运行 命令中 运行。