question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add header into parameter (ASP.NET Web API)

See original GitHub issue

Just 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
ubeyoucommented, Apr 1, 2018

Thanks. It works.

                context.OperationDescription.Operation.Parameters.Add(new SwaggerParameter
                {
                    Name = "X-Auth-User",
                    Kind = SwaggerParameterKind.Header,
                    Type = NJsonSchema.JsonObjectType.String,
                    IsRequired = true
                     });
3reactions
RicoSutercommented, Apr 1, 2018

I will add support for FromHeaderAttribute soon…

For now you can implement a custom operation processor (see wiki, same as operation filter in Swashbuckle).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found