判断网址能不能访问
http://dotnet.aspx.cc/Images/ 是否存在:" + UrlIsExist("http://dotnet.aspx.cc/Images/")); Response.Write(" http://dotnet.aspx.cc/ImagesX/ 是否存在:" + UrlIsExist("http://dotnet.aspx.cc/ImagesX/")); Response.Write(" http://xxxxx/ 是否存在:" + UrlIsExist("http://xxxxx/")); Response.Write(" hxxxxxxxxxxxxxxxxxxx 是否存在:" + UrlIsExist("hxxxxxxxxxxxxxxxxxxx")); Response.Write(" http://dotnet.aspx.cc/Images/logoSite.gif 是否存在:" + UrlIsExist("http://dotnet.aspx.cc/Images/logoSite.gif")); Response.Write(" http://dotnet.aspx.cc/Images/logoSite2.gif 是否存在:" + UrlIsExist("http://dotnet.aspx.cc/Images/logoSite2.gif"));}
发布日期:2021-11-07 06:40:21
浏览次数:3
分类:技术文章
本文共 1393 字,大约阅读时间需要 4 分钟。
看了篇文章可能会用的上,直接贴过来了。
private bool UrlIsExist(String url){ System.Uri u = null; try { u = new Uri(url); } catch { return false; } bool isExist = false; System.Net.HttpWebRequest r = System.Net.HttpWebRequest.Create(u) as System.Net.HttpWebRequest; r.Method = "HEAD"; try { System.Net.HttpWebResponse s = r.GetResponse() as System.Net.HttpWebResponse; if (s.StatusCode == System.Net.HttpStatusCode.OK) { isExist = true; } } catch (System.Net.WebException x) { try { isExist = ((x.Response as System.Net.HttpWebResponse).StatusCode != System.Net.HttpStatusCode.NotFound); } catch { isExist = (x.Status == System.Net.WebExceptionStatus.Success); } } return isExist;}protected void Page_Load(object sender, EventArgs e){ Response.Write("
原文地址:
转载地址:https://blog.csdn.net/yysyangyangyangshan/article/details/7411183 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2024年04月17日 05时21分46秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
当下热点词再学:redis缓存预热、更新、降级,限流
2019-04-27
【redis6.0.6】redis源码慢慢学,慢慢看 -- 第五天:adlist
2019-04-27
别抖,OK? 操作系统抖动现象、网络抖动与延迟、函数抖动之防抖与节流,串讲
2019-04-27
通过域名获取主机IP -- struct addrinfo
2019-04-27
【C++】算法集锦(8):从两数和问题拓展到一百数和问题
2019-04-27
【C++】算法集锦(9):背包问题
2019-04-27
【C++】算法集锦(10)通俗讲kmp算法
2019-04-27
【C++】算法集锦(12):高楼扔鸡蛋
2019-04-27
【图解】拥塞控制
2019-04-27
线程上下文切换
2019-04-27
什么是服务熔断?
2019-04-27
服务器压力过大?CPU打满?我来帮你快速检查Linux服务器性能
2019-04-27
C++面经总结之《Effective C++》(一)
2019-04-27
C++面经总结之《Effective C++》(二)
2019-04-27
这是什么“虎狼之词”啊!!!程序员的健康问题,看一线老中医怎么说!!!
2019-04-27
打开我的收藏夹 -- Python数据分析杂谈
2019-04-27
上手Pandas,带你玩转数据(1)-- 实例详解pandas数据结构
2019-04-27
上手Pandas,带你玩转数据(2)-- 使用pandas从多种文件中读取数据
2019-04-27