Để xây dựng trang Web kiểm tra xem Domain mình muốn đặt đã có người đặt hay chưa và nếu có thì kiểm tra xem ai đã đặt(thông tin chi tiết)
Bước 1: Đăng ký Script sau(đặt trong thẻ Head)
<script src="js/Library.js" type="text/javascript"></script>
<script src="js/AjaxRequest.js" type="text/javascript"></script>
<link href="Modul/popup/css/FSwprompt.css" rel="stylesheet" type="text/css" />
<script src="Modul/popup/js/jquery.min.js" type="text/javascript"></script>
<script src="Modul/popup/js/windowProm.js" type="text/javascript"></script>
Bước 2: Đăng ký Control Ajax Toolkit(trên đầu trang)
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
Bước 3: Đăng ký ScriptManager
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
Bước 4: Thiết lập giao diện tìm kiếm
<table align="center" width="800" cellpadding="0" cellspacing="0" style="background-color: #FFFFFF;
margin-top: 20px; margin-bottom: 20px;">
<tr>
<td height="50" align="center" style="background-color: #0099CC; color: #FFFFFF;
font-weight: bold">
KIỂM TRA TÊN MIỀN | WWW.DOTNET.VN
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" align="center">
<tr>
<td>
Nhập vào tên miền cần tra cứu:
</td>
</tr>
<tr>
<td valign="top">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<asp:TextBox ID="txtDomain" runat="server" Width="300px"></asp:TextBox>
</td>
<td align="right">
<asp:Button ID="btnCheck" runat="server" Text="Kiểm tra" OnClick="btnCheck_Click"
ValidationGroup="check" Width="90px" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtDomain"
Display="Dynamic" ErrorMessage="Bạn vui lòng nhập vào tên miền!" ValidationGroup="check"
Font-Italic="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td valign="top">
<asp:TabContainer ID="TabDomain" runat="server" ActiveTabIndex="0" Width="100%">
<asp:TabPanel runat="server" HeaderText="Phổ biến" ID="TabPanel1">
<ContentTemplate>
<asp:CheckBoxList ID="chkPhoBien" runat="server" RepeatColumns="3" Width="400px">
<asp:ListItem Selected="True">.com</asp:ListItem>
<asp:ListItem>.net</asp:ListItem>
<asp:ListItem>.org</asp:ListItem>
<asp:ListItem Selected="True">.vn</asp:ListItem>
<asp:ListItem Selected="True">.com.vn</asp:ListItem>
<asp:ListItem>.net.vn</asp:ListItem>
</asp:CheckBoxList>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel2" runat="server" HeaderText="Tên miền Việt Nam">
<ContentTemplate>
<asp:CheckBoxList ID="chkVietNam" runat="server" RepeatColumns="3" Width="400px">
<asp:ListItem>.ac.vn</asp:ListItem>
<asp:ListItem>.biz.vn</asp:ListItem>
<asp:ListItem Selected="True">.com.vn</asp:ListItem>
<asp:ListItem>.gov.vn</asp:ListItem>
<asp:ListItem>.edu.vn</asp:ListItem>
<asp:ListItem Selected="True">.info.vn</asp:ListItem>
<asp:ListItem>.name.vn</asp:ListItem>
<asp:ListItem>.org.vn</asp:ListItem>
<asp:ListItem Selected="True">.pro.vn</asp:ListItem>
<asp:ListItem Selected="True">.net.vn</asp:ListItem>
</asp:CheckBoxList>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel3" runat="server" HeaderText="Tên miền Quốc Tế">
<ContentTemplate>
<asp:CheckBoxList ID="chkQuocTe" runat="server" RepeatColumns="3" Width="400px">
<asp:ListItem>.asia</asp:ListItem>
<asp:ListItem Selected="True">.biz</asp:ListItem>
<asp:ListItem>.bz</asp:ListItem>
<asp:ListItem>.cc</asp:ListItem>
<asp:ListItem>.co</asp:ListItem>
<asp:ListItem>.co.uk</asp:ListItem>
<asp:ListItem Selected="True">.com</asp:ListItem>
<asp:ListItem>.com.co</asp:ListItem>
<asp:ListItem>.com.tw</asp:ListItem>
<asp:ListItem>.de</asp:ListItem>
<asp:ListItem>.eu</asp:ListItem>
<asp:ListItem>.in</asp:ListItem>
<asp:ListItem Selected="True">.info</asp:ListItem>
<asp:ListItem>.it</asp:ListItem>
<asp:ListItem>.jp</asp:ListItem>
<asp:ListItem>.me</asp:ListItem>
<asp:ListItem>.mobi</asp:ListItem>
<asp:ListItem>.name</asp:ListItem>
<asp:ListItem Selected="True">.net</asp:ListItem>
<asp:ListItem>.net.co</asp:ListItem>
<asp:ListItem>.net.tw</asp:ListItem>
<asp:ListItem>.nom.co</asp:ListItem>
<asp:ListItem>.org</asp:ListItem>
<asp:ListItem>.org.tw</asp:ListItem>
<asp:ListItem Selected="True">.pro</asp:ListItem>
<asp:ListItem>.tel</asp:ListItem>
<asp:ListItem>.tv</asp:ListItem>
<asp:ListItem>.tw</asp:ListItem>
<asp:ListItem>.us</asp:ListItem>
<asp:ListItem>.ws</asp:ListItem>
<asp:ListItem>.xxx</asp:ListItem>
</asp:CheckBoxList>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td valign="top">
<div id="divResult" runat="server">
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
Bước 5: Xử lý Sự kiện btnCheck_Click
protected void btnCheck_Click(object sender, EventArgs e)
{
string s = "";
if (TabDomain.ActiveTabIndex == 0)
{
foreach (ListItem li in chkPhoBien.Items)
{
if (li.Selected == true)
{
s += "|" + li.Text;
LoadDomain(txtDomain.Text, s.Substring(1));
}
}
}
else if (TabDomain.ActiveTabIndex == 1)
{
foreach (ListItem li in chkVietNam.Items)
{
if (li.Selected == true)
{
s += "|" + li.Text;
LoadDomain(txtDomain.Text, s.Substring(1));
}
}
}
else if (TabDomain.ActiveTabIndex == 2)
{
foreach (ListItem li in chkQuocTe.Items)
{
if (li.Selected == true)
{
s += "|" + li.Text;
LoadDomain(txtDomain.Text, s.Substring(1));
}
}
}
}
Bước 6: Hàm Load Domain
protected void LoadDomain(string Domain, string Ext)
{
int iCount = 0;
string strCheck = "";
string strToCheck = Domain;
string strDomain = Ext;
string[] strSplitEx = strDomain.Split(new char[] { '|' });
StringBuilder strOut = new StringBuilder();
strOut.Append("<b>KẾT QUẢ</b>");
strOut.Append("<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" width=\"400\">");
foreach (string strExt in strSplitEx)
{
strCheck = strToCheck + strExt;
strOut.Append(" <tr>");
strOut.Append(" <td width=\"250\" height=\"25\">");
strOut.Append(" <span id=\"domain_").Append(iCount).Append("\">");
strOut.Append(strCheck);
strOut.Append(" </span>");
strOut.Append(" </td>");
strOut.Append(" <td width=\"150\">");
strOut.Append(" <span id=\"check_").Append(iCount).Append("\"></span><br />");
strOut.Append(" <script language=\"javascript\" type=\"text/javascript\">CheckDomain('").Append(strToCheck).Append("','").Append(strExt).Append("','check_").Append(iCount).Append("');</script>");
strOut.Append(" </td>");
strOut.Append(" </tr>");
iCount++;
}
strOut.Append("</table>");
divResult.InnerHtml = strOut.ToString();
}
Bước 7: Xem chi tiết thông tin đăng ký(click dòng chữ đỏ 'Đã đăng ký'), sử dụng trang trung gian là nhanhoa để tìm xem
<asp:Label ID="lblMessage" runat="server"></asp:Label>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string Domain = Request.QueryString["domain"];
string Ext = Request.QueryString["ext"];
WebClient wc = new WebClient();
lblMessage.Text = wc.DownloadString("http://nhanhoa.com.vn/whois/?domain=" + Domain + "&ext=" + Ext + "&type=1");
}
}
Bước 8: Tạo file Whois.ashx để lấy thông tin
<%@ WebHandler Language="C#" Class="Whois" %>
using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Web.Services;
using System.Net;
public class Whois : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string strDomain = context.Request.QueryString["Domain"];
string strExt = context.Request.QueryString["ext"];
//string strHost = "http://www.matbao.net/Domain.ashx?d=" + strDomain + "&e=" + strExt;
string strHost = "http://nhanhoa.com.vn/whois/?domain=" + strDomain + "&ext=" + strExt;
try
{
context.Response.Write(GetWebContent(strHost));
}
catch (Exception ex)
{
context.Response.Write(ex.Message);
}
}
public bool IsReusable
{
get
{
return false;
}
}
public string GetWebContent(string strLink)
{
string strContent = "";
try
{
WebRequest objWebRequest = WebRequest.Create(strLink);
objWebRequest.Credentials = CredentialCache.DefaultCredentials;
WebResponse objWebResponse = objWebRequest.GetResponse();
Stream receiveStream = objWebResponse.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, System.Text.Encoding.UTF8);
strContent = readStream.ReadToEnd();
objWebResponse.Close();
readStream.Close();
}
catch (Exception ex)
{
strContent = ex.Message;
}
return strContent;
}
}
Bước 9: Nhớ là phải Add reference Control Ajax Toolkit vào thư mục Bin
Tất cả tập tin được đính kèm phía trên