check a url is from a specific site
i 开发者_运维问答want to check if a url is from youtube.com website or the mobile version of the site.
is there a robust way to do this?
checking the url contains "youtube.com" does not seem good to me. whats the proper way to do it?
Use the Uri
class to parse the URL and compare to the Host
property.
Uri uri = new Uri(myURL);
return uri.Host.Equals("youtube.com", StringComparison.InvariantCultureIgnoreCase)
I don't know a foolproof way to make sure it's youtube.com coming in, but checking REFERER is really not all that solid: the page linking to you can fake its referer header any time it wants to:
http://www.stardrifter.org/refcontrol/
It'll be interesting to see how the security gurus answer this question.
-- pete
精彩评论