【发布时间】:2026-01-16 14:15:02
【问题描述】:
我创建了一个 ASP.NET Web API 并将 Authorize 属性应用于 API 控制器。现在,我想使用 Postman 对其进行测试,但出现授权错误。
控制器代码是:
[Authorize]
[HttpPost]
public IHttpActionResult Attend([FromBody] int gigId)
{
var attendance = new Attdendance
{
GigId = gigId,
AttendeeId = User.Identity.GetUserId()
};
_context.Attdendances.Add(attendance);
_context.SaveChanges();
return Ok();
}
我的请求看起来像这样http://prntscr.com/c8wz0b
我正在使用这个高级邮递员休息客户端http://prntscr.com/c8xafd
如何在 Postman 中通过授权?
【问题讨论】:
标签: c# asp.net-web-api postman