ASP.NET Core MVC Middleware to add a 'x-basisregister-version' header to the response containing the assembly version.
Middleware component which adds the version of the assembly as header x-basisregister-version
to the response.
It is also possible to configure a custom header name to be used.
namespace Example
{
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.AspNetCore.Mvc.Middleware;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Hosting;
public class Program
{
public static async Task Main(string[] args)
{
var builder = Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(x => x.UseStartup<Startup>());
await builder.RunConsoleAsync();
}
}
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app
.UseMiddleware<AddVersionHeaderMiddleware>()
.Run(async context => await context.Response.WriteAsync("Hello World"));
}
}
}
Running this and making a request to it will result in:
$ curl -v localhost:5000
* Rebuilt URL to: localhost:5000/
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 5000 (#0)
> GET / HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 13 Jul 2020 21:01:57 GMT
< Server: Kestrel
< Transfer-Encoding: chunked
< x-version: 1.0.0.0
<
Hello World
namespace Example
{
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.AspNetCore.Mvc.Middleware;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Hosting;
public class Program
{
public static async Task Main(string[] args)
{
var builder = Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(x => x.UseStartup<Startup>());
await builder.RunConsoleAsync();
}
}
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app
.UseMiddleware<AddVersionHeaderMiddleware>("x-your-custom-header")
.Run(async context => await context.Response.WriteAsync("Hello World"));
}
}
}
Running this and making a request to it will result in:
$ curl -v localhost:5000
* Rebuilt URL to: localhost:5000/
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 5000 (#0)
> GET / HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 13 Jul 2020 21:01:57 GMT
< Server: Kestrel
< Transfer-Encoding: chunked
< x-your-custom-header: 1.0.0.0
<
Hello World