问题描述
我有两个申请.一个是在 http://localhost:59944 上运行的ASP.NET Core Web API REST Web服务.一个是使用Angular 2在 http://localhost:63888/上运行的ASP.NET Core应用程序.我想通过REST Web服务加载JSON数据.
I have got two applications. One is an ASP.NET Core Web API REST Web Service that is running at http://localhost:59944 and the other one is an ASP.NET Core application using Angular 2 running at http://localhost:63888/.I want to load JSON Data via the REST Web Service.
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似乎是未经授权的例外.
Status Code 401 seems to be unauthorized exception.
Web API项目正在使用集成的Windows身份验证.如果我通过浏览器调用Web API方法,则可以正常工作.如果我通过Angular 2调用它,则会收到错误消息.
The Web API Project is using integrated Windows authentication.If I call the Web API method via the browser it works fine. If I call it via Angular 2 I get the error message.
我已将ASP.NET Core配置为允许像这样的CORS:
I have configured ASP.NET Core to allow CORS like this:
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();
}
Angular 2中的Web Ssrvice方法调用如下所示:
The web Ssrvice method call in Angular 2 looks like this:
this.http.get('http://localhost:59944/api/myWebServiceMethod)
.map((response: Response) => response.json())
.subscribe(peopleStatistics => {
return peopleStatistics;
});
如何进行身份验证?使用Internet Explorer并直接调用Web服务时,我不必输入用户名和密码,因为浏览器使用当前登录用户的凭据进行身份验证.是否可以通过Angular 2进行网络服务调用来做到这一点?我的意思是说,无需用户通过Windows集成身份验证输入用户名和密码,就可以使用Web服务吗?
How can I do the authentication?When using Internet Explorer and calling the web service directly I do not have to enter my username and password because the browser uses the credentials of the currently logged in user to authenticate. Is it possible to do this with web Service calls via Angular 2? I mean is it possible to use the web service without the user having to enter his username and Password by using Windows integrated authentication?
推荐答案
检查 Views \ Home \ Index.cshtml
并替换:
<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
使用
<app asp-ng2-prerender-module="ClientApp/dist/main-server">Loading...</app>
或在不需要时删除 asp-prerender-module
:
<app>Loading...</app>
这篇关于在Angular 2中使用集成Windows身份验证调用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!