当前位置: 代码迷 >> ASP.NET >> 如何判断网页是否存在
  详细解决方案

如何判断网页是否存在

热度:7773   发布时间:2013-02-25 00:00:00.0
怎么判断网页是否存在?
要asp.net(c#)代码

------解决方案--------------------------------------------------------
private string GetWebContent(string Url)
{
string strResult = " ";
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
//声明一个HttpWebRequest请求
request.Timeout = 30000;
//设置连接超时时间
request.Headers.Set( "Pragma ", "no-cache ");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//返回响应
Stream streamReceive = response.GetResponseStream();
//获取服务器的文件流
Encoding encoding = Encoding.GetEncoding( "GB2312 ");
StreamReader streamReader = new StreamReader(streamReceive, encoding);
strResult = streamReader.ReadToEnd();
}
catch(Exception e)
{
Response.Write(e.Message);
}
return strResult;
}
------解决方案--------------------------------------------------------
只要在web.config里面的 <customerror> 加上errorcode 就可以自动判别出来了阿
  相关解决方案