Archive for tag: Request.Url.Port

URL fragments or parts and get Paths using HttpRequest in C#

URL fragments or parts and get Paths using HttpRequest, If we want URL fragments or parts of the URL we can get that in C# using HttpRequest as like follwoing:

In following example we have used those properties of .Net Framework Library

Below is just example URL that has taken for us to understand:

http://www.example.com:80/Products/Product-name/Detail.aspx/path/info?q=item#classic

as below

HttpRequest path and URL fragments / parts

Request.ApplicationPath: /Products

Request.CurrentExecutionFilePath: /Products/Product-name/Detail.aspx

Request.FilePath: /Products/Product-name/Detail.aspx

Request.Path: /Products/Product-name/Detail.aspx/path/info

Request.PathInfo: /path/info

Request.PhysicalApplicationPath: D:\Inetpub\wwwroot\CambiaWeb\Products\

Request.RawUrl: /Products/Product-name/Detail.aspx/path/info?q=item

Request.Url.AbsolutePath: /Products/Product-name/Detail.aspx/path/info

Request.Url.AbsoluteUri: http://www.example.com:80/Products/Product-name/Detail.aspx/path/info?q=item

Request.Url.Classic:

Request.Url.Host: www.example.com

Request.Url.LocalPath: /Products/Product-name/Detail.aspx/path/info

Request.Url.PathAndQuery: /Products/Product-name/Detail.aspx/path/info?q=item

Request.Url.Port: 80

Request.Url.Query: ?q=item

Request.Url.Scheme: http

Request.Url.Segments: /
Products/
Product-name/
Detail.aspx/
path/
info

Those are all the ways to get full, partial, fragments or parts of the URL.

THank you very much for going through this article.