我有两个应用程序。一个是运行在http://localhost:59944上的ASP.NET Core Web API REST Web服务,另一个是使用运行在http://localhost:63888/上的Angular 2的ASP.NET Core应用程序。 我想通过REST Web服务加载JSON数据。在Angular 2中使用集成Windows身份验证调用Web服务
Exception: Call to Node module failed with error: Response with status: 401 null for URL:
Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance+<InvokeExportAsync>d__7.MoveNext()
状态码401似乎是未经授权的例外。
Web API项目正在使用集成Windows身份验证。 如果我通过浏览器调用Web API方法,它工作正常。如果我通过Angular 2调用它,我会收到错误消息。
我已经配置ASP.NET核心,以允许这样的CORS:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseCors(builder =>
builder.WithOrigins("http://localhost:63888"));
app.UseMvc();
}
在角2的网络Ssrvice方法调用看起来是这样的:
this.http.get('http://localhost:59944/api/myWebServiceMethod)
.map((response: Response) => response.json())
.subscribe(peopleStatistics => {
return peopleStatistics;
});
我该怎么办认证? 当使用Internet Explorer并直接调用Web服务时,我不必输入用户名和密码,因为浏览器使用当前登录用户的凭据进行身份验证。是否有可能通过Angular 2的Web Service调用完成此操作?我的意思是可以使用Web服务,而无需用户使用Windows集成身份验证输入他的用户名和密码?
Angular 2解决方案使用'asp-prerender-module'(如果是的话,它应该在'Home \ Index.cshtml'中配置)? – Alexei
使用asp-prerender-module的解决方案:正在加载... 我现在将其更改为正在加载... 。 之后,Web服务调用工作。 –
Alexander