Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET虚拟路径在何处解析波浪线~&引用;?_Asp.net - Fatal编程技术网

ASP.NET虚拟路径在何处解析波浪线~&引用;?

ASP.NET虚拟路径在何处解析波浪线~&引用;?,asp.net,Asp.net,例如,ASP.NET虚拟路径在何处解析链接中的瓷砖~ <link rel="stylesheet" type="text/css" href="~/Css/Site.css" /> 它是在ASP.NET MVC中重定向还是重定向到操作?它从这里获得: VirtualPathUtility.ToAbsolute(contentPath, httpContext.Request.ApplicationPath); 以下是System.Web.Mvc DLL中路径帮助程序类的反射器

例如,ASP.NET虚拟路径在何处解析链接中的瓷砖
~

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

它是在ASP.NET MVC中重定向还是
重定向到操作?

它从这里获得:

VirtualPathUtility.ToAbsolute(contentPath, httpContext.Request.ApplicationPath);
以下是System.Web.Mvc DLL中
路径帮助程序
类的反射器输出:

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在每个runat=server控件中使用应用程序的根目录转换波浪号(~)。它是该属性的等效项。

请参见

ASP.NET包括Web应用程序 根运算符(~),可以使用 在服务器中指定路径时 控制。ASP.NET解决了以下问题:~ 运算符到当前值的根 应用你可以使用~ 运算符与文件夹一起使用 指定基于路径的路径的步骤 当前根

基本上,tilde的目的是,即使您将网站部署到不同的地方,您也可以拥有正确解析的路径。相对路径无法轻松完成此任务,因为控件可能呈现在网站中的不同文件夹中。绝对路径无法实现这一点,因为您的网站可能被部署到不同的位置——如果没有其他情况,那么本地测试部署与实时服务器的发布部署就是如此


Server.MapPath可以用于类似的原因。

您的问题没有任何意义。我的问题是基于这个问题“要查看链接”,我认为问题不在asp.net-mvc中,而在IIS中。谢谢,不,这是不等价的。AppDomainAppVirtualPath是“包含当前应用程序域中托管的应用程序的目录的虚拟路径”(虚拟目录)。它肯定与应用程序的根目录不同,至少在IIS7中是这样。