I am having troubles with including files into my website after publishing it on server. The website is called "shop" and located in wwwroot folder. The website doesn't read scripts, which are located like this: shop/app_themes/grey/js/site.js. How to give the correct path to script files? I used ~, ../, ../../ and doesn't help..
Asked
Active
Viewed 487 times
-1
Arunprasanth K V
- 20,733
- 8
- 41
- 71
programmer
- 1
- 2
2 Answers
0
User Server.MapPath Methos the details are below
Server.MapPath(path)
You can use Resolve Url method.
Example
-
1Doesn't help. That will get you the local path, not the relative server url. – Patrick Hofman Dec 01 '14 at 09:11
-
I have an error for js file "uncaught reference error $ is not defined (anonymous function)". can it be the problem? – programmer Dec 01 '14 at 09:52
0
if u want host url then try this
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;
}
or else you want physical path then try this
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;
}
}
Arunprasanth K V
- 20,733
- 8
- 41
- 71