Add header into parameter (ASP.NET Web API)
See original GitHub issueJust moved my swagger dependency to NSwag. It’s great, however, there is no way to add a header (e.g X-Auth-User) as parameter for ASP.NETin Swagger UI. As FromHeader only available for ASP.NET Core, what’s the way to display header param?
I tried custom FromHeaderAttribute but it fails.
public IHttpActionResult PostAuthentication([FromHeader("X-Auth-User")] string username)
in Swashbuckle, it can use IOperationFilter and
operation.parameters.Add(new Parameter
{
name = "X-Auth-User",
@in = "header",
type = "string",
required = true
});
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:12 (4 by maintainers)
Top Results From Across the Web
c# - Web Api How to add a Header parameter for all API in ...
Just a quick note to say that the [FromHeader] attribute is only available for WebAPI instances which use ASP.Net Core, not full .Net....
Read more >How to Add Custom Headers in ASP.NET Core Web API
In this article, we are going to learn how to add custom headers in ASP.NET Core Web API and how to enable it...
Read more >Parameter Binding in ASP.NET Web API - ASP.NET 4.x
Describes how Web API binds parameters and how to customize the binding process in ASP.NET 4.x.
Read more >Add a Header parameter to .NET Core API in Swagger
Add Header parameter to .NET Core API in Swagger OpenAPI V3.0 using IOperationFilter interface. Add custom headers, security tokens by overriding Apply() ...
Read more >Adding a Required HTTP Header to Your Swagger UI With ...
Let's first look at a simple swagger setup as our baseline before we add everything for our HTTP Header Field. ... config.SwaggerDoc( "v1"...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks. It works.
I will add support for FromHeaderAttribute soon…
For now you can implement a custom operation processor (see wiki, same as operation filter in Swashbuckle).