ASP.NET – HttpRequest.Url -Difference between Url.OriginalString and Url.AbsoluteUri

In the context of the HttpRequest.Url property, both Url.OriginalString and Url.AbsoluteUri provide information about the URL of the request. However, there is a subtle difference between the two:

  1. Url.OriginalString: This property returns the original URL string that was used to create the Uri instance. It includes any special characters or percent-encoded representations that might be present in the URL. For example, if the original URL contained spaces, special characters, or non-ASCII characters, OriginalString would preserve them without any modification.
  2. Url.AbsoluteUri: This property returns the absolute URL string, which is the canonical representation of the URL. It represents the normalized form of the URL with all necessary escaping and encoding applied. It ensures that the URL is valid and conforming to the URL specification. The AbsoluteUri property provides a valid and usable URL that can be used for making subsequent requests or resolving the resource.

To summarize, Url.OriginalString gives you the exact original string as it was provided, while Url.AbsoluteUri provides the normalized and escaped URL that can be safely used for further processing or making requests.

Leave a comment

Your email address will not be published. Required fields are marked *