Problem with Uri.MakeRelative() method

N

Nathan Sokalski

When using the MakeRelative() method of the Uri class, I have noticed that
the Query and Fragment are never returned. I ran the following code and
recieved the following results:

Dim initialUri1 As New Uri("http://www.mydomain.com/index.aspx")

Dim initialUri2 As New Uri("http://www.mydomain.com/dir1/index.aspx")

Dim initialUri3 As New Uri("http://www.mydomain.com/dir1/dir2/index.aspx")

Dim fragmentUri As New Uri("http://www.mydomain.com/dir1/index.aspx#QUOTES")

Dim queryUri As New
Uri("http://www.mydomain.com/dir1/index.aspx?qname=myself")

Response.Write("Result for fragmentUri: " &
initialUri1.MakeRelative(fragmentUri) & "<br>")

Response.Write("Result for queryUri: " & initialUri1.MakeRelative(queryUri)
& "<br>")

Response.Write("Result for fragmentUri: " &
initialUri2.MakeRelative(fragmentUri) & "<br>")

Response.Write("Result for queryUri: " & initialUri2.MakeRelative(queryUri)
& "<br>")

Response.Write("Result for fragmentUri: " &
initialUri3.MakeRelative(fragmentUri) & "<br>")

Response.Write("Result for queryUri: " & initialUri3.MakeRelative(queryUri))


This gave me the following results:

Result for fragmentUri: dir1/index.aspx
Result for queryUri: dir1/index.aspx
Result for fragmentUri:
Result for queryUri:
Result for fragmentUri: ../index.aspx
Result for queryUri: ../index.aspx

As you can see, the correct path is always returned but the Query and
Fragment properties are completely ignored. Is there a way to return the
Query or Fragment without manually adding it?
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top