//If you have users enter URLs and you would like to check them to make sure they exist before you //save them to the database, here is the code:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Net.Sockets" %>
<script runat="server">
public void Page_Load(Object sender, EventArgs E) {
string url = "www.google.com";
if(UrlIsValid(url)) {
Response.Write("The URL '" + url + "' is valid.");
} else {
Response.Write("The URL '" + url + "' is NOT valid.");
}
}
public static bool UrlIsValid(string smtpHost)
{
bool br = false;
try {
IPHostEntry ipHost = Dns.Resolve(smtpHost);
br = true;
}
catch (SocketException se) {
br = false;
}
return br;
}
script>
|