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