我正在编写一个Angular 4应用程序,需要从Asp.Net WebApi获取一些数据。我们使用Windows身份验证来保护WebAPI,我想知道如何将用户的Windows身份从我的Angular应用程序传递到WebApi。我找到了一些示例,这些示例涉及将应用程序与MVC应用程序嵌套在一起,但我希望将UI与MVC分开。有没有一种方法可以在不向我的Angular网站添加.net mvc的情况下完成这个任务?
我正在编写一个Angular 4应用程序,需要从Asp.Net WebApi获取一些数据。我们使用Windows身份验证来保护WebAPI,我想知道如何将用户的Windows身份从我的Angular应用程序传递到WebApi。我找到了一些示例,这些示例涉及将应用程序与MVC应用程序嵌套在一起,但我希望将UI与MVC分开。有没有一种方法可以在不向我的Angular网站添加.net mvc的情况下完成这个任务?
@Injectable()
export class SecurityService {
private baseUrl = 'http://localhost:64706/api/security/';
private auth: Auth;
private options = new RequestOptions({ withCredentials: true });
constructor(private http: Http) {
console.log('Creating Service');
console.log('Service Pre Http');
this.http.get(this.baseUrl, this.options)
.map((res) => this.extractData<Auth>(res))
.subscribe(newItem => {
console.log('Service Subscribe');
this.auth = newItem;
})
}
public isUser(): Observable<boolean> | boolean {
if (!this.auth) {
return this.http.get(this.baseUrl, this.options)
.map(res => {
this.auth = this.extractData<Auth>(res);
return this.auth.isUser;
});
}
else {
return this.auth.isUser;
}
}
private extractData<T>(res: Response) {
if (res.status < 200 || res.status >= 300) {
throw new Error('Bad response status: ' + res.status);
}
const body = res.json ? res.json() : null;
return <T>(body || {});
}
}
export class Auth {
isAdmin: boolean;
isUser: boolean;
}
this.User.Identity.IsAuthenticated
。import { RequestOptions } from '@angular/http';
。 - XAMlMAX