1

I’m trying to determine whether or not a given string is a valid url or not. And in my scenario, the url can have parameters:

  • www.example.com -> OK
  • example.test -> OK (although there’s no .test TLD)
  • example.com/page.htm?abc=123 -> OK
  • xxx/xxx.jpg -> Not OK
  • xxx -> Not OK

I’ve tried the Uri.TryCreate method, Uri.TryCreate(url, UriKind.Absolute, null);, but it accepts pretty much anything that has an http:// prefix, i.e. “http://xxx/” is OK.

I can’t use an HTTP request to check/ping the site for performance reasons.

Any suggestions?

2
  • Why isn't http://xxx OK? See, for example, to. (Your browser may choke on that; you may need to add a trailing period) Commented Oct 2, 2011 at 14:26
  • There's nothing wrong with http://xxx/ Commented Oct 2, 2011 at 14:26

1 Answer 1

2

It sounds like you want to call Uri.TryCreate(url, UriKind.Absolute, out result), then check that result.HostName contains a .

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

1 Comment

Thanks, I think your tip did the tricks. I'll play around some more with the Uri object and see if I can something useful out of the properties. :)

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.