我在WEB API中设置此标头但在客户端
上获得响应HttpContext.Current.Response.Headers.Add("x-total-records", documentData.TotalItemsCount.ToString(CultureInfo.InvariantCulture));
为什么它没有响应
答案 0 :(得分:0)
在你的mvc函数中执行此操作
Request.Properties.Add("x-total-records", documentData.TotalItemsCount.ToString(CultureInfo.InvariantCulture));
并创建一个像这样的过滤器
public class CustomHeaderFilter : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
if (actionExecutedContext.Request.Properties.Any(p => p.Key == "x-total-records"))
{
actionExecutedContext.Response.Content.Headers.Add("Access-Control-Expose-Headers", "x-total-records");
actionExecutedContext.Response.Content.Headers.Add("x-total-records", actionExecutedContext.Request.Properties["x-total-records"].ToString());
}
}
}
Hopfuly这将解决您的问题