Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have my current page url as http://localhost:3000/Account/login . In which I want to have a string storing only the first part of the url
i.e Http://localhost:3000/.

How can I do that?

What I have tried:

tried the code as

uri urlBuilder = HttpContext.Current.Request.Url;
string returnUrl = urlBuilder?.Scheme + "://" + urlBuilder?.Authority;


This works but I don't think this is the best way to approach it.

Can anyone please let me know whether there is ny other better way we can handle this
Posted
Updated 7-Jan-21 5:31am

1 solution

Simple:
C#
Uri url = HttpContext.Current.Request.Url;
string returnUrl = url.GetLeftPart(UriPartial.Authority);
Uri.GetLeftPart(UriPartial) Method (System) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900