0
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.

Edited by Nick Evan: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by dnanetwork
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.