gpt4 book ai didi

asp.net - ASP.NET 虚拟路径在哪里解析波浪号 "~"?

转载 作者:行者123 更新时间:2023-12-02 09:53:54 26 4
gpt4 key购买 nike

ASP.NET虚拟路径在哪里解析链接中的波形符~,例如

<link rel="stylesheet" type="text/css" href="~/Css/Site.css" />

它是重定向,还是 ASP.NET MVC 中的 RedirectToAction

最佳答案

它从这里获取:

VirtualPathUtility.ToAbsolute(contentPath, httpContext.Request.ApplicationPath);

以下是 System.Web.Mvc DLLPathHelpers 类的反射器输出:

private static string GenerateClientUrlInternal(HttpContextBase httpContext, string contentPath)
{
if (string.IsNullOrEmpty(contentPath))
{
return contentPath;
}
if (contentPath[0] == '~')
{
string virtualPath = VirtualPathUtility.ToAbsolute(contentPath, httpContext.Request.ApplicationPath);
string str2 = httpContext.Response.ApplyAppPathModifier(virtualPath);
return GenerateClientUrlInternal(httpContext, str2);
}
NameValueCollection serverVariables = httpContext.Request.ServerVariables;
if ((serverVariables == null) || (serverVariables["HTTP_X_ORIGINAL_URL"] == null))
{
return contentPath;
}
string relativePath = MakeRelative(httpContext.Request.Path, contentPath);
return MakeAbsolute(httpContext.Request.RawUrl, relativePath);
}

关于asp.net - ASP.NET 虚拟路径在哪里解析波浪号 "~"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4563235/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com