Invalid path for MapPath
-
I'm getting the exception "Invalid path for MapPath - A virtual path is expected" when trying to convert a path to a physical path using Server.MapPath(). This, I believe, is caused by the fact that I'm using an absolute path (like "http://www.fluiduitoolkit.com/design/assemblies/index.xml"), rather than a virtual path (like "design/assemblies/index.xml"). So I need to use a virtual path. All very well, but how does one convert an absolute path to a virtual path in ASP.NET? I haven't found a method that does this, nor have I found a property that gives me the application's web path (NOT physical path). Do you know how I could do this? Thanks in advance!
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi -
I'm getting the exception "Invalid path for MapPath - A virtual path is expected" when trying to convert a path to a physical path using Server.MapPath(). This, I believe, is caused by the fact that I'm using an absolute path (like "http://www.fluiduitoolkit.com/design/assemblies/index.xml"), rather than a virtual path (like "design/assemblies/index.xml"). So I need to use a virtual path. All very well, but how does one convert an absolute path to a virtual path in ASP.NET? I haven't found a method that does this, nor have I found a property that gives me the application's web path (NOT physical path). Do you know how I could do this? Thanks in advance!
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma GandhiWhy not just create a mthod that strips out the domain part of the url leaving only the virtual path?
// Steve McLenithan
Family Guy: Season 2 - Episode 8
-
Why not just create a mthod that strips out the domain part of the url leaving only the virtual path?
// Steve McLenithan
Family Guy: Season 2 - Episode 8
Hmm... Well, I suppose you could take out everything before the first single "/" . See, I want the domain name to not be hard-coded.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi -
Hmm... Well, I suppose you could take out everything before the first single "/" . See, I want the domain name to not be hard-coded.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhijdunlap wrote: See, I want the domain name to not be hard-coded. Of course;)
// Steve McLenithan
Family Guy: Season 2 - Episode 8
-
jdunlap wrote: See, I want the domain name to not be hard-coded. Of course;)
// Steve McLenithan
Family Guy: Season 2 - Episode 8
How's this?
public string AbsToVirtualPath(string spath)
{
int index=0;
//most accurate method of checking for abs. path
if(spath.IndexOf("://")==-1) return spath;
//find the first "/" that's not double, and retrieve
//what's beyond that
while(index!=-1)
{
index=spath.IndexOf("/",index);
if(index==-1) return spath;
if(spath.Substring(index+1,1)=="/")
{
index+=2;
}
else
{
return spath.Substring(index+1,spath.Length-(index+1));
}
}
}"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi -
How's this?
public string AbsToVirtualPath(string spath)
{
int index=0;
//most accurate method of checking for abs. path
if(spath.IndexOf("://")==-1) return spath;
//find the first "/" that's not double, and retrieve
//what's beyond that
while(index!=-1)
{
index=spath.IndexOf("/",index);
if(index==-1) return spath;
if(spath.Substring(index+1,1)=="/")
{
index+=2;
}
else
{
return spath.Substring(index+1,spath.Length-(index+1));
}
}
}"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma GandhiLooks good to me.
// Steve McLenithan
Family Guy: Season 2 - Episode 8
-
Looks good to me.
// Steve McLenithan
Family Guy: Season 2 - Episode 8
Only problem is... The path: http://www.fluiduitoolkit/design/assemblies/index.xml becomes: http://www.fluiduitoolkit/design/**design/**assemblies/index.xml ...because it maps the path starting at /design instead of the root. Looks like this method won't work. I've gotta somehow get the path root, and strip that off.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi -
Only problem is... The path: http://www.fluiduitoolkit/design/assemblies/index.xml becomes: http://www.fluiduitoolkit/design/**design/**assemblies/index.xml ...because it maps the path starting at /design instead of the root. Looks like this method won't work. I've gotta somehow get the path root, and strip that off.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi