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