我知道這可能不是現成的方式,但我使用這些來確保URLS在我的應用程序中是正確的,沒有問題。這些在我的頁面/視圖的基類可用...
public static string ApplicationRootUrl()
{
string port = String.Empty;
if (HttpContext.Current.Request.ServerVariables["SERVER_PORT"] != null && HttpContext.Current.Request.ServerVariables["SERVER_PORT"].ToString() != "80" && HttpContext.Current.Request.ServerVariables["SERVER_PORT"].ToString() != "443")
{
port = String.Concat(":", HttpContext.Current.Request.ServerVariables["SERVER_PORT"].ToString());
}
string protocol = "http://";
if (HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"] != null && HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"] != "0")
{
protocol = "https://";
}
return String.Concat(protocol, String.Concat(HttpContext.Current.Request.Url.Host, port, HttpContext.Current.Request.ApplicationPath, '/').Replace(@"//", @"/").ToLower());
}
/// <summary>
/// Expands a virtual URL to an absolute URL using the current application root url
/// </summary>
/// <param name="url"></param>
public static string ExpandUrl(string url)
{
if (url.Trim().StartsWith("~"))
{
return String.Concat(ApplicationRootUrl(), url.Substring(1).Replace("//", "/"));
}
if (url.Trim().StartsWith("www", StringComparison.OrdinalIgnoreCase))
{
return String.Concat("http://", url);
}
return url;
}
如果您希望它們都位於相同的應用程序路徑下,請在Visual Studio中轉到您的Web項目屬性,單擊Web並更改「虛擬路徑」以匹配您的生產應用程序名稱。 – Zachary
嘗試將虛擬路徑從'/ MyIntranet'改爲'/',但文件未被選中。 –
如果您查看網頁的網址/來源,它現在是否顯示應用程序名稱?在您的本地開發框中,「JScript.js」的工作路徑是什麼? – Zachary