Ahmed Mujtaba
Ahmed Mujtaba

Reputation: 2248

Request.RequestUri.GetLeftPart(UriPartial.Authority) returns null value

I'm trying to get the base of url using the following command : string baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority); which returns a null value. Request.RequestUri returns http://10.71.34.1:63026/api/member/profilethumb/PetePentreath but I only want http://10.71.34.1:63026/ and the rest of the url chopped off. How do I do this?

Upvotes: 0

Views: 1036

Answers (1)

Habib
Habib

Reputation: 223352

You cause Uri.Scheme, Uri.Host and Uri.Port property to build your output. You can also use UriBuilder class and get the required Uri like:

Uri RequestUri = Request.RequestUri;
Uri modifiedUri = new UriBuilder(RequestUri.Scheme, RequestUri.Host,RequestUri.Port).Uri;

modifiedUri will have http://10.71.34.1:63026/

Upvotes: 1

Related Questions