Herhangi bir web sitesine erisim isteginde bulununca eger yanit alabiliyorsak, internet’e baglantimiz var demektir.


Default.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Internet Baglanti Testi |
www.yazilimcik.com</title>
<style type="text/css">
.style1
{
width: 60%;
}
.style2
{
width: 231px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr bgcolor="#336699">
<td class="style2">
&nbsp;
</td>
<td>
&nbsp;
</td>
</tr>
<tr>
<td bgcolor="#66CCFF" class="style2">
&nbsp;<asp:Label ID="lblBaslik" runat="server" Font-Bold="True" Font-Size="Large"
ForeColor="#003366" Text="Internet Baglanti Kontrolü"></asp:Label><br />
</td>
<td align="center">
&nbsp;
<asp:Label ID="lblAciklama" runat="server" ForeColor="Red" Font-Bold="true"></asp:Label>
</td>
</tr>
<tr>
<td align="center" class="style2">
&nbsp;&nbsp;
</td>
<td align="center" class="style2">
<asp:Panel ID="pnlWebsite" runat="server">
&nbsp;
<asp:LinkButton ID="lbWebsite" runat="server" OnClick="lbWebsite_Click" Font-Bold="True"
ForeColor="#000066">Baglanti’yi Yeniden Kontrol Et!</asp:LinkButton>
</asp:Panel>
</td>
</tr>
<tr>
<td align="center" class="style2">
&nbsp;
</td>
<td align="center">
&nbsp;www.yazilimcik.com
</td>
</tr>
</table>
</div>
</form>
</body>
</html>



Default.aspx.cs


// Internet Baglanti Testi | www.yazilimcik.com | Ali AKYILDIRIM
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
// Internet Baglanti Testi |
www.yazilimcik.com | Ali AKYILDIRIM


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (WebRequestTest())
{
pnlWebsite.Visible = false;
lblAciklama.Text = "Internet Baglantisi Var..!";
}
else
{
pnlWebsite.Visible = true;
lblAciklama.Text = "Internet Baglantisi Yok..!";
}
}
//Mutlaka bir web adresi girilmelidir:
string url = "
http://www.yazilimcik.com"; //Site’yi www.google.com olarak degistirebilirsiniz..
public static bool WebRequestTest()
{
try
{
//Mutlaka bir web adresi girilmelidir:
string url = "
http://www.yazilimcik.com"; //Site’yi www.google.com olarak degistirebilirsiniz..
if (url != string.Empty)
{
System.Net.WebRequest myRequest = System.Net.WebRequest.Create(url);
System.Net.WebResponse myResponse = myRequest.GetResponse();
}
else
{
Exception ex = new Exception();
ex.Message.ToString();
}
}

catch (System.Net.WebException)
{
return false;
}
return true;
}
protected void lbWebsite_Click(object sender, EventArgs e)
{
Response.Redirect(url);
}
}
// Internet Baglanti Testi |
www.yazilimcik.com | Ali AKYILDIRIM