2

Another beginner question, I'm afraid...

I was wondering if someone could tell me the easiest and most efficient way of getting the fully qualified domain name (e.g. www.google.com) from a UrlEncoded string in ASP.Net (C#).

For example:

 http%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dsome%20things%20i%20searched%20for

Would give me:

 www.google.com

(Or basically anything where I can check the domain to make sure it's correct.)

I'm guessing the first step might be to UrlDecode, but since this is how I'm getting the string, I thought I'd mention it incase it's easier Encoded.

Thanks for any help!

2 Answers 2

4
(new URI(System.Web.HttpServerUtility.UrlDecode(url))).Host

For reference:

URI - http://msdn.microsoft.com/en-us/library/system.uri.aspx

HttpServerUtility - http://msdn.microsoft.com/en-us/library/6196h3wt.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Every now and then I type new Url( xxx ) and get surprised it's not what I want.
0

I believe you can use Request.Url.host to get the hostname.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.