mousemat24
asked on
How to make a path relative?
Hi there
Really need some help:
I have this URL
private const string DummyPageUrl = "~/Service.aspx";
I also have a method called
private void HitPage()
{
WebClient client = new WebClient();
var url = HttpRuntime.AppDomainAppVi rtualPath + DummyPageUrl; // this is wrong?
client.DownloadData(url);
}
How do I make the path relative i.e
http://test.com/books/Service.aspx
Thanks
Really need some help:
I have this URL
private const string DummyPageUrl = "~/Service.aspx";
I also have a method called
private void HitPage()
{
WebClient client = new WebClient();
var url = HttpRuntime.AppDomainAppVi
client.DownloadData(url);
}
How do I make the path relative i.e
http://test.com/books/Service.aspx
Thanks
ASKER
just done that, I get an error:
Could not find file 'C:\RunningAsService.aspx' .
private const string DummyPageUrl = "RunningAsService.aspx";
.
.
.
WebClient client = new WebClient();
var url = HttpRuntime.AppDomainAppVi rtualPath + DummyPageUrl;
client.DownloadData(url);
Could not find file 'C:\RunningAsService.aspx'
private const string DummyPageUrl = "RunningAsService.aspx";
.
.
.
WebClient client = new WebClient();
var url = HttpRuntime.AppDomainAppVi
client.DownloadData(url);
ASKER
if I put private const string DummyPageUrl = "/RunningAsService.aspx";
I get this error:
The UNC path should be of the form \\server\share.
I get this error:
The UNC path should be of the form \\server\share.
ASKER
if I put private const string DummyPageUrl = "~/RunningAsService.aspx";
I get this error:
Could not find a part of the path 'C:\~\RunningAsService.asp x'.
I get this error:
Could not find a part of the path 'C:\~\RunningAsService.asp
ASKER
note: this is in the global.asax file
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you are running this on client side, then you won't be able to get the server path, the virtual directory mapping is suppose to hide it as a part of security. You are suppose to know the complete url if you are accessing this from client side.
On server side, you can use :
var url = HttpContext.Current.Server .MapPath(" ~/Service. aspx");
-Rahul Gade
On server side, you can use :
var url = HttpContext.Current.Server
-Rahul Gade
private void HitPage()
{
WebClient client = new WebClient();
var url = HttpRuntime.AppDomainAppVi
client.DownloadData(url);
}