asp.net-core - ASP.NET Core Web API FromHeader 绑定 x-api-key 标头
问题描述
我有一个x-api-key
要绑定到控制器参数的标头。我尝试了下面的代码,但参数仍然为空。
[HttpGet]
public ActionResult Get([FromHeader] xApiKey) {
var apikey = xApiKey;
}
解决方案
发布此问题 5 分钟后,我在这里找到了答案。所以使用name
FromHeader的属性。
[HttpGet]
public ActionResult Get([FromHeader(Name = "x-api-key")] apiKey) {
// code here
}
推荐阅读
- android - 如何使用phoneNumber或电子邮件ID作为android中的参数从通讯录中获取联系人姓名
- python - 在 Numpy 数组中搜索子字符串值
- node.js - 无需全域授权即可访问 Google Workspace Admin SDK?
- android - Android createCaptureSession 冻结 UI 2 秒
- javascript - Openlayers 6 延迟交互
- javascript - 使用 jQuery UI 将特定日期变灰不起作用
- reactjs - 缩放和平移画布的反应包
- javascript - ckeditor5 从内容中删除视频标签
- c++ - ubuntu 中 C++ 的 Notepad++ NppExec 脚本
- python - Groupby 并删除 NaN 行,同时在 Pandas 中保留一个