Skip to content

Instantly share code, notes, and snippets.

@dylanberry
Last active May 24, 2019 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanberry/1984e587ea553c6fe7e11d39c2d8b12e to your computer and use it in GitHub Desktop.
Save dylanberry/1984e587ea553c6fe7e11d39c2d8b12e to your computer and use it in GitHub Desktop.
using Microsoft.AspNetCore.Mvc.Filters;
namespace VersionCheck.API.VersionCheck
{
public class MinimumClientVersionFilter : IActionFilter
{
private readonly IVersionCheckService _versionCheckHelper;
public MinimumClientVersionFilter(IVersionCheckService versionCheckHelper)
{
_versionCheckHelper = versionCheckHelper;
}
public void OnActionExecuting(ActionExecutingContext context)
{
_versionCheckHelper.PerformVersionCheck(context.HttpContext.Request);
}
public void OnActionExecuted(ActionExecutedContext context)
{
}
}
}
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using VersionCheck.API.VersionCheck;
namespace VersionCheck.API.Controllers
{
[ServiceFilter(typeof(MinimumClientVersionFilter))]
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2" };
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment