[C#] 於Code Level驗證URL

有時制造表格時, 須要去驗證用戶輸入的URL是否正確, 這個可以透過Attribute 完成. 但若果得到的URL是從app.config 或其他檔案而來, 那就變得有須要在code level 進行一次檢查.

Uri url = null;
if(Uri.TryCreate(Convert.ToString(value), UriKind.Absolute, out url)){
 // True statement.
} else {
 // False statement.
}
About C.H. Ling 262 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.