1
我用下面的代码到一个自定义标题添加到操作:如何阅读Swashbuckle中的自定义标题?
public class RequestIdParameter : IOperationFilter
{
public void Apply(Swashbuckle.Swagger.Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation == null) return;
if (operation.parameters == null)
{
operation.parameters = new List<Parameter>();
}
var requestParameter = new Parameter
{
description = "RequestId",
@in = "header",
name = "RequestId",
required = true,
type = "string"
};
operation.parameters.Add(requestParameter);
}
}
但现在我需要阅读该值。我想这个代码,但自定义页眉不存在:
System.Web.HttpContext.Current.Items.contains("requestId")
参数的名称是'RequestId',但你寻找参数'requestId'。你确定它不是一个区分大小写的问题吗? –
尝试HttpContext.Current.Request.Headers [“requestid”] – Nico