asp.net 检测是否是有效连接地址

//是否是有效连接地址

  public bool IsWebURL(string URL)
    {
        System.Net.WebResponse myRepTest;
        System.Net.WebRequest myTest = System.Net.WebRequest.Create(URL);
        myTest.Timeout = 5000;
        bool link = true;
        try { myRepTest = myTest.GetResponse(); }
        catch { link = false; }
        return link;
    }

如果返回真就是有效的网址可以打开,否则不是。

原文地址:https://www.cnblogs.com/Loyalty/p/2879699.html