1
Answer

URL- Exists or not

rpsin88

rpsin88

21y
2.1k
1
In my web application , i have to validate whether url entered by user exists or not. say for e.g if user enters www.theurlnotexists.com - i have to display an error message incorrect url/domain not exists if user enters www.yahoo.com - i have to display an entered url is correct and store it in DB. how to find out whether url entered exists or not.? Thanks in advance Ananth
Answers (1)
1
chrishornberger

chrishornberger

NA 277 0 21y
Well, you really have little choice but to fire up a HttpWebRequest object and hit it. YOu'll either get a response object or a trappable error. A simpler way ( if you don't care about the WHOLE url ) might be to parse out just the prefix and domain identifier ( www.theurlnotexists.com ) and try to ping it, but I suspect you'll do better just hitting the entire url. You'll want to thread it out so your app doesn't sit hung for a small amount of time while DNS tries to resolve a bad name (http://wwww.thisurlcould&$neverExists.comm/) or while the server is chewing on the full url you've parsed it (http//:www.yahoo.com/valid/domain/but/bad/directories/and?url.parameter.values=111)