Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 476997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:32:48+00:00 2026-05-13T00:32:48+00:00

I need to combine two URL’s that both contain .Path information. I would like

  • 0

I need to combine two URL’s that both contain .Path information.

I would like to use Uri to give me possibility to .TryCreate(), so I can catch malformed URL’s.

The problem that I’m facing is that the base URI path seems to be ignored when I merge the absolute and the relative URI:

Uri absoluteUri= new Uri("http://hostname/path/", UriKind.Absolute);
Uri relativeUri = new Uri("/my subsite/my page.aspx?my=query", UriKind.Relative);
Uri resultUri;
if (!Uri.TryCreate(absoluteUri, relativeUri, out resultUri))
      // handle errors

Output of the above is:

http://hostname/my%20subsite/my%20page.aspx?my=query

I would like it to be:

http://hostname/path/my%20subsite/my%20page.aspx?my=query

Is there a way to combine URLs that both contain path information using the Uri class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:32:48+00:00Added an answer on May 13, 2026 at 12:32 am

    Your relative URI should be relative, i.e., remove first slash (or add a period),

    string relative = "/my subsite/my page.aspx?my=query";
    
    Uri test1= new Uri(relative.Substring(1), UriKind.Relative); // without 'root'
    Uri test2= new Uri("." + relative, UriKind.Relative);        // with 'current'
    

    Working example:

    Uri baseUri = new Uri("http://hostname/path/");
    string relative = "/my subsite/my page.aspx?my=query";
    
    Uri test1 = new Uri(baseUri, relative);              // original string
    Uri test2 = new Uri(baseUri, relative.Substring(1)); // without 'root' character
    Uri test3 = new Uri(baseUri, "." + relative);        // with 'current' character
    
    Console.WriteLine(test1.OriginalString); // wrong
    Console.WriteLine(test2.OriginalString); // right!
    Console.WriteLine(test3.OriginalString); // right!
    

    So, you probably should deal with your relative part like this:

    if (relative.StartsWith("/"))
        relative = "." + relative;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to combine two urls, but it seems that UriBuilder doesn't support url's
Need a function like: function isGoogleURL(url) { ... } that returns true iff URL
I have two .htaccess files that I need to combine into one. The first
I have the following two T-SQL statements that I really need to combine: SELECT
I have 3 byte arrays in C# that I need to combine into one.
I need to combine two 32-bit values to create a 64-bit value. I'm looking
Need a small hand here im trying to combine two functions to create a
I'd like to combine two lists. If I have the following two lists: {a,b,c,d}
I have two IList<Traffic> I need to combine. Traffic is a simple class: class
I have a MySql database with three tables I need to combine in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.