Feedback

Prüfen ob URL gültig ist

Sprache: C#

Prüft ob die URL aufgelößt werden kann.
/// <summary>
/// Check if the URL is valid.
/// </summary>
/// <param name="smtpHost">The URL.</param>
/// <returns></returns>
public static bool IsUrlValid(string smtpHost)
{
    bool response = false;
    try
    {
        IPHostEntry ipHost = Dns.Resolve(smtpHost);
        response = true;
    }
    catch (SocketException se)
    {
        response = false;
    }
    return response;
}
/// <summary>
/// Check if the URL is valid.
/// </summary>
/// <param name="smtpHost">The URL.</param>
/// <returns></returns>
public static bool IsUrlValid(string smtpHost)
{
    bool response = false;
    try
    {
        IPHostEntry ipHost = Dns.Resolve(smtpHost);
        response = true;
    }
    catch (SocketException se)
    {
        response = false;
    }
    return response;
}

1 Kommentar

  1. VB
    Jetzt geht es so:
    [code]
    Function URLOk(ByVal Tx As String) As Boolean
    Try
    Dim hostInfo As System.Net.IPHostEntry _
    = System.Net.Dns.GetHostEntry(Tx)
    Return True
    Catch
    Return False
    End Try
    End Function
    [/code]