Tag: asp.net core 2.0

JS Fetch API无法使用具有Authorize属性的ASP.NET Core 2控制器

我在客户端有以下代码: fetch(“/music/index”, { headers: { “Content-Type”: “application/json” } }) .then(response => { if (!response.ok) { throw response; } return response.json(); }) .then(json => { console.log(“Done! It’s all good”); }) .catch(response => console.log(response)); 不幸的是,这甚至没有到达MusicController (服务器端),它看起来如下(简化以说明要点): [Authorize] public class MusicController : Controller { public async Task Index() { IEnumerable songs = await _songsRepository.GetAll(); return Json(songs); } } […]