How to determine if a relative path is outside of a virtual path
<p>I'm using the following function to convert paths into a valid Virtual Path:</p>

<pre><code>public string GetFullPath(string path)
{
    Ensure.Argument.NotNullOrEmpty(path, "path");

    if (path[0] == '~') // a virtual path e.g. ~/assets/style.less
    {
        return path;
    }

    if (VirtualPathUtility.IsAbsolute(path)) // an absolute path e.g. /assets/style.less
    {
        return VirtualPathUtility.ToAppRelative(path,
            HostingEnvironment.IsHosted ? HostingEnvironment.ApplicationVirtualPath : "/");
    }

    // otherwise, assume relative e.g. style.less or ../../variables.less
    return VirtualPathUtility.Combine(VirtualPathUtility.AppendTrailingSlash(currentFileDirectory), path);
}
</code></pre>

<p>This passes all my tests other than for when the input <code>path</code> is a relative path, <strong>above</strong> the website directory.</p>

<p>For example given a <code>currentFileDirectory</code> of <code>~/foo/bar</code> and a relative path of <code>../../../</code> I want to detect this and attempt to fix the path.</p>
