1
我有一個使用Identity Server 4並註冊和登錄路由的API。但是我用[Authorized]
保護的那些給我404
有或沒有授權標頭。如果我從路線中刪除[Authorized]
,它會被擊中。可能是什麼問題?C#.Net核心API使用Identity Server 4的授權路由
這是控制器:
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
namespace Security.API.Controllers
{
[Route("[controller]")]
public class AccountController : Controller
{
private readonly IAccountService accountService;
public AccountController(IAccountService accountService)
{
this.accountService = accountService;
}
[HttpGet("")]
public string Get()
{
return "You are seeing this because account controller is working fine!";
}
[Authorize]
[HttpGet("getauthorized")]
public string GetAuthorized()
{
return "This is authorized okay.";
}
...
首先路由中得到的命中,第二個沒有
那麼它應該是這樣的未來,但這是爲了測試目的。無論如何不應該擊中路線?我的意思是,路由不知道它是客戶端還是服務器,它聽取我指定的請求:) – Norgul
實際上它有點知道,因爲我們必須以不同的方式配置中間件,如果它的客戶端或Web API – JayDeeEss