Problem with Uri.MakeRelative() method

Discussion in 'ASP .Net Web Controls' started by Nathan Sokalski, May 29, 2005.

  1. 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?
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, May 29, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Harris
    Replies:
    0
    Views:
    6,382
    Simon Harris
    May 10, 2005
  2. Nathan Sokalski

    Problem with Uri.MakeRelative() method

    Nathan Sokalski, May 29, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    901
    Nathan Sokalski
    May 29, 2005
  3. Stanimir Stamenkov
    Replies:
    1
    Views:
    2,476
    Stanimir Stamenkov
    Aug 17, 2005
  4. Pavel
    Replies:
    2
    Views:
    1,651
    Peter Flynn
    Aug 4, 2004
  5. etheriau
    Replies:
    1
    Views:
    669
    Pavel
    Aug 23, 2004
Loading...

Share This Page