本文介绍了内网网址检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public partial class _Default : System.Web.UI.Page
{
public static bool UrlIsValid(string url)
{ HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Proxy = null;
try
{ HttpWebResponse response = (HttpWebResponse)request.GetResponse();
return true; }
catch //If exception thrown then couldn't get response from address
{ return false; }
}
private void Page_Load(object sender, EventArgs e)
{ Response.BufferOutput = true;
string url = (" http:///");
if (UrlIsValid(url))
{ Response.Redirect(url); }
else
{ Response.Redirect("http://www.yahoo.com"); }
非常感谢您将此代码提供给我,但我也希望它也检查Intranet网站.因此,在那种情况下,尽管服务器已启动并且正在工作,但我仍要给公司Intranet网站提供服务时,我应该如何修改代码cos,并将其重定向到yahoo.我希望它仅在该Intranet站点内部站点已关闭或无法正常工作时才进行重定向.
请提供帮助..
Thank you so much for giving me this code, but i want it to check for intranet site also. So in that case how should i modify the code cos when i am giving the company intranet site though the server is up and working it gets redirected to yahoo. I want it to redirect only if that intranet site internal site is down or not working .
Please do help..
推荐答案
这篇关于内网网址检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!