google-site-verification=ECX1M6_Vb39ty4VtQDXQce6wOjmPTxSettd3hTIZb9Q

C# Check If Internet Connection is Available

random

C# Check If Internet Connection is Available

Networking - C# Checking Internet Connection

While developing a web application in asp.net, this is very important to check whether the internet connection is available or not. 

So in this post I will show how to detect working internet connection and what is the fastest and most efficient way to check for Internet connection in asp.net web application using C#. Find the below code :-


check my internet connection,check for an Internet connection,How to check internet connectivity, how to check internet connection, check internet is working,How to check if internet connectivity available or not in C#,C# Determine if internet connection is available,How to check Internet Connection is Working or Not using c#
Check Internet Connectivity
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bool flag = CheckForInternetConnection();
            if (flag == true)
            { Response.Write("Internet connection is working."); }
            else
            { Response.Write("Internet connection is not working."); }
        }
    }
    public bool CheckForInternetConnection()
    {
        try
        {
            using (var client = new WebClient())
            using (var stream = client.OpenRead("http://www.google.com"))
            {
                return true;
            }
        }
        catch
        {
            return false;
        }
    }
}

I hope you will enjoy the development tips while programming with C#. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome. 

Also If you like this article, don't forget to share this article with your friends and colleagues.
C# Check If Internet Connection is Available Reviewed by Ravi Kumar on 12:43 AM Rating: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017

Contact Form

Name

Email *

Message *

Powered by Blogger.