Get version from request header

private string GetVersionFromAcceptHeaderVersion(HttpRequestMessage request)
string temp = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, “Controllers”);

if (System.Web.HttpContext.Current.Request.Headers[“X-Api-Version”] != null)
IEnumerable<string> headerValues = request.Headers.GetValues(“X-Api-Version”);
if (headerValues != null)
return headerValues.FirstOrDefault();
return string.Empty;
var latestversion = Directory.GetDirectories(temp)
.OrderByDescending(dir => dir)
return latestversion.Substring(latestversion.Length – 1);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s