在将文件发布到服务器上之后,将文件包含到我的网站中时遇到了麻烦。 website
被称为“商店”,位于wwwroot
文件夹中。 website
不读取脚本,它们的位置如下:shop/app_themes/grey/js/site.js.
如何为脚本文件提供正确的路径?我使用~, ../, ../../
并没有帮助..
答案 0 :(得分:0)
答案 1 :(得分:0)
如果你想要主机网址,那么试试这个
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;
}
}