我想从WEB API获取一些数据,但在 API 调试控制台中收到如下错误消息:
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.InvalidOperationException: Endpoint WebAPI_1.Controllers.DataCTXController.Get (WebAPI_1) contains authorization metadata, but a middleware was not found that supports authorization.
Configure your application startup by adding app.UseAuthorization() inside the call to Configure(..) in the application startup code. The call to app.UseAuthorization() must appear between app.UseRouting() and app.UseEndpoints(...).
at Microsoft.AspNetCore.Routing.EndpointMiddleware.ThrowMissingAuthMiddlewareException(Endpoint endpoint)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Run Code Online (Sandbox Code Playgroud)
我使用Postman发送请求。我尝试在行之间移动 app.UseAuthorization() 并自己解决一些问题,但仍然一无所获,这就是为什么我需要你的帮助。这是我的 Startup.cs 代码:
using System; …Run Code Online (Sandbox Code Playgroud) 我正在学习Angular和ASP.NET,所以我想制作简单的 WebApi,但在邮递员中一切正常,唯一的问题是我的 Angular 应用程序,我不知道在哪里,所以我在这里寻求建议。
这是我的 Angular .ts 脚本,负责从本地 api 获取数据:
import { Component, OnInit } from "@angular/core";
import { HttpClientModule } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable()
export class ConfigService {
constructor(private http: HttpClient) { }
}
@Component({
selector: "app-user",
templateUrl: "./user.component.html",
styleUrls: ["./user.component.css"]
})
export class UserComponent implements OnInit {
values: any;
constructor(private http: HttpClient) {}
ngOnInit() {
this.getValues();
console.log();
}
getValues() {
this.http.get('http://localhost:5000/api/DataCTX').subscribe(response => { …Run Code Online (Sandbox Code Playgroud)