asp.net 判断url是否有效

来源:互联网 发布:跌荡一百年知乎 编辑:程序博客网 时间:2024/05/18 16:37
  using System.Net;
 try
       {string path="http://202.106.139.25/TDP/ShowPicture?imgUrl=/ttlprog/app/wl81/openhotel/HOTO/output/"+ds.Tables[3].Rows[i]["PropertyID"].ToString().Substring(2,3)+"/WJ/"+ds.Tables[3].Rows[i]["PropertyID"].ToString().Substring(2,3)+"WJ01.jpg";
        WebRequest webRequest = WebRequest.Create(@path);// 建立web请求
        webRequest.Timeout = 2 * 1000;
      WebResponse webResponse = webRequest.GetResponse(); // 获得web服务器的回应
  //有效执行下面这行     
 ds.Tables[3].Rows[i]["img"]="http://202.106.139.25/TDP/ShowPicture?imgUrl=/ttlprog/app/wl81/openhotel/HOTO/output/"+ds.Tables[3].Rows[i]["PropertyID"].ToString().Substring(2,3)+"/WJ/"+ds.Tables[3].Rows[i]["PropertyID"].ToString().Substring(2,3)+"WJ01.jpg";
       }
    
                
     
    catch//否则执行下面
    {ds.Tables[3].Rows[i]["img"]="images/nopic.jpg";} 
原创粉丝点击