【发布时间】:2010-07-18 07:18:57
【问题描述】:
命名空间 WebApplication4 { 公共部分类_默认:System.Web.UI.Page {
public static bool UrlIsValid(string url)
{
bool br = false;
try
{
IPHostEntry ipHost = Dns.Resolve(url);
br = true;
}
catch (SocketException)
{
br = false;
}
return br;
}
private void Page_Load(object sender, EventArgs e)
{
string url = "http://www.srv123.com";
WebRequest wr = WebRequest.Create(url);
使用 (HttpWebResponse 响应 = (HttpWebResponse)wr.GetResponse ()) { 如果(response.StatusCode == HttpStatusCode.OK) { response.Close();
Response.Redirect(url);
}
else
{
Response.Redirect("http://www.yahoo.com");
}
当我给谷歌时,它会重定向到谷歌,但是当我给一个无效的网址时,它不会重定向到雅虎,就像我给的一样。我在重定向之前给出了响应
【问题讨论】: