[Fixes #2896] Made UrlHelper.Content behavior consistent with MVC 5
This commit is contained in:
parent
94fad918a3
commit
b5237b29b5
|
|
@ -122,12 +122,19 @@ namespace Microsoft.AspNet.Mvc
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual string Content(string contentPath)
|
public virtual string Content(string contentPath)
|
||||||
{
|
{
|
||||||
if (contentPath == null)
|
if (string.IsNullOrEmpty(contentPath))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
else if (contentPath[0] == '~')
|
||||||
|
{
|
||||||
|
var segment = new PathString(contentPath.Substring(1));
|
||||||
|
var applicationPath = _httpContext.Request.PathBase;
|
||||||
|
|
||||||
return GenerateClientUrl(_httpContext.Request.PathBase, contentPath);
|
return applicationPath.Add(segment).Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return contentPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
@ -142,17 +149,6 @@ namespace Microsoft.AspNet.Mvc
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GenerateClientUrl([NotNull] PathString applicationPath,
|
|
||||||
[NotNull] string path)
|
|
||||||
{
|
|
||||||
if (path.StartsWith("~/", StringComparison.Ordinal))
|
|
||||||
{
|
|
||||||
var segment = new PathString(path.Substring(1));
|
|
||||||
return applicationPath.Add(segment).Value;
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GenerateUrl(string protocol, string host, string path, string fragment)
|
private string GenerateUrl(string protocol, string host, string path, string fragment)
|
||||||
{
|
{
|
||||||
// We should have a robust and centrallized version of this code. See HttpAbstractions#28
|
// We should have a robust and centrallized version of this code. See HttpAbstractions#28
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
[InlineData("/", "~/", "/")]
|
[InlineData("/", "~/", "/")]
|
||||||
[InlineData("/myapproot", "~/", "/myapproot/")]
|
[InlineData("/myapproot", "~/", "/myapproot/")]
|
||||||
[InlineData("", "~/Home/About", "/Home/About")]
|
[InlineData("", "~/Home/About", "/Home/About")]
|
||||||
|
[InlineData("/", "~", "/")]
|
||||||
[InlineData("/myapproot", "~/Content/bootstrap.css", "/myapproot/Content/bootstrap.css")]
|
[InlineData("/myapproot", "~/Content/bootstrap.css", "/myapproot/Content/bootstrap.css")]
|
||||||
public void Content_ReturnsAppRelativePath_WhenItStartsWithToken(string appRoot,
|
public void Content_ReturnsAppRelativePath_WhenItStartsWithToken(string appRoot,
|
||||||
string contentPath,
|
string contentPath,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue