【发布时间】:2014-12-01 17:18:36
【问题描述】:
在服务器上发布文件后,我无法将文件包含到我的网站中。 website 被称为“商店”,位于wwwroot 文件夹中。 website 不读取脚本,其位置如下:shop/app_themes/grey/js/site.js. 如何为脚本文件提供正确的路径?我用~, ../, ../../ 并没有帮助..
【问题讨论】:
标签: asp.net
在服务器上发布文件后,我无法将文件包含到我的网站中。 website 被称为“商店”,位于wwwroot 文件夹中。 website 不读取脚本,其位置如下:shop/app_themes/grey/js/site.js. 如何为脚本文件提供正确的路径?我用~, ../, ../../ 并没有帮助..
【问题讨论】:
标签: asp.net
【讨论】:
如果你想要主机网址,那么试试这个
public string GetHostUrl()
{
var request = HttpContext.Current.Request;
var appUrl = HttpRuntime.AppDomainAppVirtualPath;
if (appUrl == null || appUrl == "" || appUrl != "/")
{
appUrl += "/";
}
var baseUrl = string.Format("{0}://{1}{2}", request.Url.Scheme, request.Url.Authority, appUrl);
return baseUrl;
}
或者你想要物理路径然后试试这个
public string GetPhysicalPath()
{
string PhysicalPath = "";
if (Application["instancePath"] != null && Convert.ToString(Application["instancePath"]) != "")
{
PhysicalPath = Convert.ToString(Application["instancePath"]);
}
else
{
PhysicalPath = Server.HtmlEncode(Request.PhysicalApplicationPath);
}
return PhysicalPath;
}
}
【讨论】: