Paths, relative, virtual etc

J

JJ

I'm confused about paths.

I have a functionn that uses the mappath method, which I think requires a
virtual path (is that the same as a relative path?).

But this doesn't always work as the path can take the form of the following:
1. /directory/images/xyz.gif (works fine)
2. http://localhost:1234/www.mytestwebsite.com/directory/images/xyz.gif
(doesn't work)
3. http:///www.someremotesite.com/directory/images/abc.gif (doesn't work)

So my questions are:
a) How can I check to see if the url is a virtual one or not?
b) How to I make a url virtual or relative?
c) How do I check if the url is refering to a file on the local server?

(with part c I assume I would check to see if the url contains the local
root domain? but I am unsure how I obtain the root domain?)

Thanks in advance,

JJ
 
E

Eliyahu Goldin

MapPath works only with virtual (yes, it is the same as relative for this
matter) paths. If you get first an absolute path, you can try to decide
whether it points to your application's folder, reduce it to a virtual path
and call MapPath. You can find some useful properties in the System.Uri
class.
 
J

JJ

Eliyahu,

thanks for the hints, but I'm a bit confused with the first step - how I
find out programmatically if the path is absolute or virtual?

JJ


Eliyahu Goldin said:
MapPath works only with virtual (yes, it is the same as relative for this
matter) paths. If you get first an absolute path, you can try to decide
whether it points to your application's folder, reduce it to a virtual
path and call MapPath. You can find some useful properties in the
System.Uri class.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


JJ said:
I'm confused about paths.

I have a functionn that uses the mappath method, which I think requires a
virtual path (is that the same as a relative path?).

But this doesn't always work as the path can take the form of the
following:
1. /directory/images/xyz.gif (works fine)
2. http://localhost:1234/www.mytestwebsite.com/directory/images/xyz.gif
(doesn't work)
3. http:///www.someremotesite.com/directory/images/abc.gif (doesn't work)

So my questions are:
a) How can I check to see if the url is a virtual one or not?
b) How to I make a url virtual or relative?
c) How do I check if the url is refering to a file on the local server?

(with part c I assume I would check to see if the url contains the local
root domain? but I am unsure how I obtain the root domain?)

Thanks in advance,

JJ
 
E

Eliyahu Goldin

In the Uri class:

Property IsAbsoluteUri will tell you if the path is absolute.

Method MakeRelativeUri will help you to convert an absolute path to
relative.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


JJ said:
Eliyahu,

thanks for the hints, but I'm a bit confused with the first step - how I
find out programmatically if the path is absolute or virtual?

JJ


Eliyahu Goldin said:
MapPath works only with virtual (yes, it is the same as relative for this
matter) paths. If you get first an absolute path, you can try to decide
whether it points to your application's folder, reduce it to a virtual
path and call MapPath. You can find some useful properties in the
System.Uri class.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


JJ said:
I'm confused about paths.

I have a functionn that uses the mappath method, which I think requires
a virtual path (is that the same as a relative path?).

But this doesn't always work as the path can take the form of the
following:
1. /directory/images/xyz.gif (works fine)
2. http://localhost:1234/www.mytestwebsite.com/directory/images/xyz.gif
(doesn't work)
3. http:///www.someremotesite.com/directory/images/abc.gif (doesn't
work)

So my questions are:
a) How can I check to see if the url is a virtual one or not?
b) How to I make a url virtual or relative?
c) How do I check if the url is refering to a file on the local server?

(with part c I assume I would check to see if the url contains the local
root domain? but I am unsure how I obtain the root domain?)

Thanks in advance,

JJ
 
J

JJ

I'd got as far as trying to convert the string to a uri:

ImageSrcUri = new Uri(currentSrc);


but it seems to fail when the string is of the form:
/www.myvisualstudiowebsite.com/Uploads/fbloggs/Image/header.jpg

saying:
Invalid URI: The format of the URI could not be determined.

What is wrong with this relative URI?


Also, in order to find out if the file refered to in a url (an absolute URL)
I was going to find out if it starts with the application root domain. In
case I change the domain, I wanted to get it programmatically. I tried:
Uri RootUri = new Uri(VirtualPathUtility.ToAbsolute("~"));

- but got the same invlide URI error.

In Visual Studio, the uri is of the form
"http://localhost:1234/www.mywebsite.com/. This is a little confusing but I
guess I am after the http://localhost:1234 bit.



JJ






Eliyahu Goldin said:
In the Uri class:

Property IsAbsoluteUri will tell you if the path is absolute.

Method MakeRelativeUri will help you to convert an absolute path to
relative.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


JJ said:
Eliyahu,

thanks for the hints, but I'm a bit confused with the first step - how I
find out programmatically if the path is absolute or virtual?

JJ


Eliyahu Goldin said:
MapPath works only with virtual (yes, it is the same as relative for
this matter) paths. If you get first an absolute path, you can try to
decide whether it points to your application's folder, reduce it to a
virtual path and call MapPath. You can find some useful properties in
the System.Uri class.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


I'm confused about paths.

I have a functionn that uses the mappath method, which I think requires
a virtual path (is that the same as a relative path?).

But this doesn't always work as the path can take the form of the
following:
1. /directory/images/xyz.gif (works fine)
2. http://localhost:1234/www.mytestwebsite.com/directory/images/xyz.gif
(doesn't work)
3. http:///www.someremotesite.com/directory/images/abc.gif (doesn't
work)

So my questions are:
a) How can I check to see if the url is a virtual one or not?
b) How to I make a url virtual or relative?
c) How do I check if the url is refering to a file on the local server?

(with part c I assume I would check to see if the url contains the
local root domain? but I am unsure how I obtain the root domain?)

Thanks in advance,

JJ
 
E

Eliyahu Goldin

Uri standard is defined in a document RFC 2396. Google for it and you will
find plenty of resources.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


JJ said:
I'd got as far as trying to convert the string to a uri:

ImageSrcUri = new Uri(currentSrc);


but it seems to fail when the string is of the form:
/www.myvisualstudiowebsite.com/Uploads/fbloggs/Image/header.jpg

saying:
Invalid URI: The format of the URI could not be determined.

What is wrong with this relative URI?


Also, in order to find out if the file refered to in a url (an absolute
URL) I was going to find out if it starts with the application root
domain. In case I change the domain, I wanted to get it programmatically.
I tried:
Uri RootUri = new Uri(VirtualPathUtility.ToAbsolute("~"));

- but got the same invlide URI error.

In Visual Studio, the uri is of the form
"http://localhost:1234/www.mywebsite.com/. This is a little confusing but
I guess I am after the http://localhost:1234 bit.



JJ






Eliyahu Goldin said:
In the Uri class:

Property IsAbsoluteUri will tell you if the path is absolute.

Method MakeRelativeUri will help you to convert an absolute path to
relative.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


JJ said:
Eliyahu,

thanks for the hints, but I'm a bit confused with the first step - how I
find out programmatically if the path is absolute or virtual?

JJ


message MapPath works only with virtual (yes, it is the same as relative for
this matter) paths. If you get first an absolute path, you can try to
decide whether it points to your application's folder, reduce it to a
virtual path and call MapPath. You can find some useful properties in
the System.Uri class.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


I'm confused about paths.

I have a functionn that uses the mappath method, which I think
requires a virtual path (is that the same as a relative path?).

But this doesn't always work as the path can take the form of the
following:
1. /directory/images/xyz.gif (works fine)
2.
http://localhost:1234/www.mytestwebsite.com/directory/images/xyz.gif
(doesn't work)
3. http:///www.someremotesite.com/directory/images/abc.gif (doesn't
work)

So my questions are:
a) How can I check to see if the url is a virtual one or not?
b) How to I make a url virtual or relative?
c) How do I check if the url is refering to a file on the local
server?

(with part c I assume I would check to see if the url contains the
local root domain? but I am unsure how I obtain the root domain?)

Thanks in advance,

JJ
 
J

JJ

I realise this is a relative uri, but I don't see why this is not a valid
relative Uri type.
It works in an image tag, but not when I try to use it as Uri type?


Eliyahu Goldin said:
Uri standard is defined in a document RFC 2396. Google for it and you will
find plenty of resources.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


JJ said:
I'd got as far as trying to convert the string to a uri:

ImageSrcUri = new Uri(currentSrc);


but it seems to fail when the string is of the form:
/www.myvisualstudiowebsite.com/Uploads/fbloggs/Image/header.jpg

saying:
Invalid URI: The format of the URI could not be determined.

What is wrong with this relative URI?


Also, in order to find out if the file refered to in a url (an absolute
URL) I was going to find out if it starts with the application root
domain. In case I change the domain, I wanted to get it programmatically.
I tried:
Uri RootUri = new Uri(VirtualPathUtility.ToAbsolute("~"));

- but got the same invlide URI error.

In Visual Studio, the uri is of the form
"http://localhost:1234/www.mywebsite.com/. This is a little confusing but
I guess I am after the http://localhost:1234 bit.



JJ






Eliyahu Goldin said:
In the Uri class:

Property IsAbsoluteUri will tell you if the path is absolute.

Method MakeRelativeUri will help you to convert an absolute path to
relative.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Eliyahu,

thanks for the hints, but I'm a bit confused with the first step - how
I find out programmatically if the path is absolute or virtual?

JJ


message MapPath works only with virtual (yes, it is the same as relative for
this matter) paths. If you get first an absolute path, you can try to
decide whether it points to your application's folder, reduce it to a
virtual path and call MapPath. You can find some useful properties in
the System.Uri class.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


I'm confused about paths.

I have a functionn that uses the mappath method, which I think
requires a virtual path (is that the same as a relative path?).

But this doesn't always work as the path can take the form of the
following:
1. /directory/images/xyz.gif (works fine)
2.
http://localhost:1234/www.mytestwebsite.com/directory/images/xyz.gif
(doesn't work)
3. http:///www.someremotesite.com/directory/images/abc.gif (doesn't
work)

So my questions are:
a) How can I check to see if the url is a virtual one or not?
b) How to I make a url virtual or relative?
c) How do I check if the url is refering to a file on the local
server?

(with part c I assume I would check to see if the url contains the
local root domain? but I am unsure how I obtain the root domain?)

Thanks in advance,

JJ
 
E

Eliyahu Goldin

Likely, it doesn't comply with the RFC 2396. If you don't care about
following strictly the Uri standard, don't use the Uri class and write your
own url parsing code.

You can try to open another thread Re: Uri parsing and hope someone more
experienced in that than me will help you.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


JJ said:
I realise this is a relative uri, but I don't see why this is not a valid
relative Uri type.
It works in an image tag, but not when I try to use it as Uri type?


Eliyahu Goldin said:
Uri standard is defined in a document RFC 2396. Google for it and you
will find plenty of resources.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


JJ said:
I'd got as far as trying to convert the string to a uri:

ImageSrcUri = new Uri(currentSrc);


but it seems to fail when the string is of the form:
/www.myvisualstudiowebsite.com/Uploads/fbloggs/Image/header.jpg

saying:
Invalid URI: The format of the URI could not be determined.

What is wrong with this relative URI?


Also, in order to find out if the file refered to in a url (an absolute
URL) I was going to find out if it starts with the application root
domain. In case I change the domain, I wanted to get it
programmatically. I tried:
Uri RootUri = new Uri(VirtualPathUtility.ToAbsolute("~"));

- but got the same invlide URI error.

In Visual Studio, the uri is of the form
"http://localhost:1234/www.mywebsite.com/. This is a little confusing
but I guess I am after the http://localhost:1234 bit.



JJ






message In the Uri class:

Property IsAbsoluteUri will tell you if the path is absolute.

Method MakeRelativeUri will help you to convert an absolute path to
relative.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Eliyahu,

thanks for the hints, but I'm a bit confused with the first step - how
I find out programmatically if the path is absolute or virtual?

JJ


message MapPath works only with virtual (yes, it is the same as relative for
this matter) paths. If you get first an absolute path, you can try to
decide whether it points to your application's folder, reduce it to a
virtual path and call MapPath. You can find some useful properties in
the System.Uri class.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


I'm confused about paths.

I have a functionn that uses the mappath method, which I think
requires a virtual path (is that the same as a relative path?).

But this doesn't always work as the path can take the form of the
following:
1. /directory/images/xyz.gif (works fine)
2.
http://localhost:1234/www.mytestwebsite.com/directory/images/xyz.gif
(doesn't work)
3. http:///www.someremotesite.com/directory/images/abc.gif (doesn't
work)

So my questions are:
a) How can I check to see if the url is a virtual one or not?
b) How to I make a url virtual or relative?
c) How do I check if the url is refering to a file on the local
server?

(with part c I assume I would check to see if the url contains the
local root domain? but I am unsure how I obtain the root domain?)

Thanks in advance,

JJ
 
J

JJ

Correct me if I'm wrong but, it seems that you can't make a relative url
into a Uri type.
I quote from the msdn docs:
"Relative URIs (for example, "/new/index.htm") must be expanded with respect
to a base URI so that they are absolute. The MakeRelative method is provided
to convert absolute URIs to relative URIs when necessary."

Only after using the MakeRelative method does the IsAbsolute test come into
play.

In which case this method will not solve my problem of ascertaining whether
the string is a relative path/url or absolute url.

JJ


Eliyahu Goldin said:
Likely, it doesn't comply with the RFC 2396. If you don't care about
following strictly the Uri standard, don't use the Uri class and write
your own url parsing code.

You can try to open another thread Re: Uri parsing and hope someone more
experienced in that than me will help you.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


JJ said:
I realise this is a relative uri, but I don't see why this is not a valid
relative Uri type.
It works in an image tag, but not when I try to use it as Uri type?


Eliyahu Goldin said:
Uri standard is defined in a document RFC 2396. Google for it and you
will find plenty of resources.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


I'd got as far as trying to convert the string to a uri:

ImageSrcUri = new Uri(currentSrc);


but it seems to fail when the string is of the form:
/www.myvisualstudiowebsite.com/Uploads/fbloggs/Image/header.jpg

saying:
Invalid URI: The format of the URI could not be determined.

What is wrong with this relative URI?


Also, in order to find out if the file refered to in a url (an absolute
URL) I was going to find out if it starts with the application root
domain. In case I change the domain, I wanted to get it
programmatically. I tried:
Uri RootUri = new Uri(VirtualPathUtility.ToAbsolute("~"));

- but got the same invlide URI error.

In Visual Studio, the uri is of the form
"http://localhost:1234/www.mywebsite.com/. This is a little confusing
but I guess I am after the http://localhost:1234 bit.



JJ






message In the Uri class:

Property IsAbsoluteUri will tell you if the path is absolute.

Method MakeRelativeUri will help you to convert an absolute path to
relative.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Eliyahu,

thanks for the hints, but I'm a bit confused with the first step -
how I find out programmatically if the path is absolute or virtual?

JJ


message MapPath works only with virtual (yes, it is the same as relative for
this matter) paths. If you get first an absolute path, you can try
to decide whether it points to your application's folder, reduce it
to a virtual path and call MapPath. You can find some useful
properties in the System.Uri class.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


I'm confused about paths.

I have a functionn that uses the mappath method, which I think
requires a virtual path (is that the same as a relative path?).

But this doesn't always work as the path can take the form of the
following:
1. /directory/images/xyz.gif (works fine)
2.
http://localhost:1234/www.mytestwebsite.com/directory/images/xyz.gif
(doesn't work)
3. http:///www.someremotesite.com/directory/images/abc.gif (doesn't
work)

So my questions are:
a) How can I check to see if the url is a virtual one or not?
b) How to I make a url virtual or relative?
c) How do I check if the url is refering to a file on the local
server?

(with part c I assume I would check to see if the url contains the
local root domain? but I am unsure how I obtain the root domain?)

Thanks in advance,

JJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top