amespace WebApplication4
{
public partial class _Default : 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.google.com";
bool str;
if (UrlIsValid(url))
{
str = true;
}
else
{
str = false;
}
if (str==true)
{
Response.Redirect(url);
}
else
{
Response.Redirect("http://www.yahoo.com");
}
I used the above code, but it gets redirected to yahoo regardless of whether the url is up or not. I want it to redirect to google if it is working , and if i provide some other invalid site , i want it to redirect to yahoo.