Server : ASP.net Core Web API
Client : WinForms app using Refit and sending its version with each request (as a header)
How does the server check the client requests version, if it is wrong then reply by calling a controller action VersionError?
This code does not end the request:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseAuthorization();
app.Use(async (context, next) =>
{
foreach (var header in context.Request.Headers)
{
Console.WriteLine($"{context.Request.Path} : {header.Key}={header.Value}");
if (header.Key == "CLIENT-VERSION" && header.Value != "5")
{
context.Request.Method = "GET";
context.Request.Path = "/api/Error/VersionError";
}
}
await next();
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
[ApiController]
[Route("api/[controller]/[action]")]
public class ErrorController : ControllerBase
{
[HttpGet]
public Message<string> VersionError()
{
var reply = new Message<string>(errorMessage: "version error");
return reply;
}
}