如何使用asp.net检查网址是否存在?

编程入门 行业动态 更新时间:2024-10-26 08:22:20
本文介绍了如何使用asp检查网址是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何使用asp检查网址是否存在? 如何准确使用以下代码段?

How to check if a web url exists, using asp? how to use below snippet accurately?

public bool urlExists(string url) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.AllowRedirect = false; HttpWebResponse res = (HttpWebResponse)req.GetResponse(); //How to check if url exists - code?? if(/*exists code*/) return true; else return false; }

推荐答案

检查HttpStatus。它是Response对象的属性。 最好的问候, MRB Check the HttpStatus. It is a property of the Response object. Best Regards, MRB

我尝试了一些完美的代码如果有url它会显示结果否则 显示msgs。 Hi, I tried some code it works perfect If there is url it shows results otherwise shows msgs. WebRequest req = WebRequest.Create("www.codeproject"); WebResponse res; try { res = req.GetResponse(); } catch (Exception ed) { goto sd; } Stream sg = res.GetResponseStream(); StreamReader sr = new StreamReader(sg); resdiv.InnerHtml = sr.ReadToEnd(); goto fg; sd: resdiv.InnerHtml = "Sorry no such url exists "; ; fg:;

上述代码的含义是如果url存在则存在如果它不存在就没有例外它会提升webnull Execption。 我们处理这个例子,因为如果url不存在我们写下我们要做的事情。 我希望你能理解我说的话。 一切顺利

The meaning of above code is if url has exists there is no exeception if it not exists it''ll raise webnull Execption. We handle that execption in that we write what we''ve to do if url not exists. I hope you''ll understand what i said. All the best

您好, 您可以查看网址是否存在或者不是关注网址。 public bool urlExists(string url) { HttpWebRequest req =(HttpWebRequest)WebRequest.Create( url); req.AllowAutoRedirect = false; HttpWebResponse res =(HttpWebResponse)req.GetResponse(); if(res.StatusCode == HttpStatusCode.OK) 返回true; else 返回false; } Hello, You can check the web url is exist or not on following url. public bool urlExists(string url) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.AllowAutoRedirect = false; HttpWebResponse res = (HttpWebResponse)req.GetResponse(); if (res.StatusCode == HttpStatusCode.OK) return true; else return false; }

更多推荐

如何使用asp.net检查网址是否存在?

本文发布于:2023-11-10 03:01:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574166.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   是否存在   网址   net   asp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!