本文介绍了哪里ASP.NET虚拟路径解决波浪"〜"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里ASP.NET虚拟路径解决链接波浪号,例如:

Where does ASP.NET virtual path resolve the tilde ~ in the links, for example

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

是否重定向或 RedirectToAction 在ASP.NET MVC?

Does it redirect, or RedirectToAction in ASP.NET MVC?

推荐答案

它得到它从这里:

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

下面是反射输出 PathHelpers 类的 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虚拟路径解决波浪&QUOT;〜&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 01:53