在定义标题时,我想使用[ValidateAntiForgeryToken]
验证我的“FORM”HTTP请求。问题是,我正在尝试使用Postman将原始数据作为application / json发送。如果我只是将__RequestVerificationToken
值作为表单数据发送它就可以了。但我认为我们不能同时将POST请求作为“原始”和“表单数据”发送。
那么,我该怎么办?
控制器:
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult PhoneBook([FromBody]PersonnelFilterReq filterList)
{
return Ok("FINALLY WORKED!!!!");
}
模型(在POST方法中使用):
using System.Collections.Generic;
namespace GebzeShared.Modules.HR.Personnel.RequestModels
{
/// <summary>
/// Personel sayfaları için genel request metodu
/// </summary>
public class PersonnelFilterReq
{
/// <summary>
/// Arama Değeri
/// </summary>
public string SearchValue { get; set; }
/// <summary>
/// Filtre Listesi
/// </summary>
public ICollection<FilterList> Filter { get; set; }
/// <summary>
///
/// </summary>
public int TotalCount { get; set; }
/// <summary>
///
/// </summary>
public int PageNumber { get; set; }
/// <summary>
///
/// </summary>
public string OrderColumn { get; set; }
}
/// <summary>
///
/// </summary>
public class FilterList
{
/// <summary>
/// Filterinin Adı
/// </summary>
public string FilterName { get; set; }
/// <summary>
/// Filtrenin Değeri
/// </summary>
public ICollection<string> FilterValue { get; set; }
}
}
发送JSON“原始”数据:
{
"SearchValue": "ShiroiTora",
"Filter": [
{
"FilterName": "DepartmentIdList",
"FilterValue": [
"1",
"2",
"3"
]
}
],
"TotalCount": "1000",
"PageNumber": "1",
"OrderColumn": "Name"
},
//{
// "__RequestVerificationToken": "*some_token_here"
//}
发送“表格数据”: