Skip to content

Instantly share code, notes, and snippets.

@testfirstcoder
Created March 2, 2016 15:16
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 testfirstcoder/939f3ad7b85f4c757205 to your computer and use it in GitHub Desktop.
Save testfirstcoder/939f3ad7b85f4c757205 to your computer and use it in GitHub Desktop.
Request root path (host path + virtual path)
public static class HttpRequestMessageHelpers
{
private const char separator = '/';
public static string GetRootPath(this HttpRequestMessage message)
=> GetHostPath(message) + separator + GetVirtualPath(message);
private static string GetHostPath(HttpRequestMessage message)
=> message.RequestUri.GetLeftPart(UriPartial.Authority).TrimEnd(separator);
private static string GetVirtualPath(HttpRequestMessage message)
=> message.GetRequestContext().VirtualPathRoot.TrimStart(separator);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment