青海网站建设、网络推广最好的公司--您身边的网站建设专家,马上拿起电话,联系我们:0971-8235355   
青海西宁网站建设、网站制作公司-西宁威势电子信息服务有限公司 首页 |  公司简介 |  网站建设 |  网络推广 |  空间租用 |  域名注册 |  企业邮局 |  网络安全 |  网站编程 |  客服中心 |  联系我们 |  人才招聘
 
西宁威势最新网站制做案例展示
Lastest Project
 
西宁网站建设  
当前位置为:首页 >> .NET编程 >> 正文  
[原创] asp.net+c# 写的域名是否注册的查询页面

文章来源: 西宁威势电子信息服务有限公司     发布时间:2010-11-21    浏览次数:8355   

    大体思路是网上看来的,网上那篇文章的查询方法是先建两个页面,第一个页面是查询的一些CHECKBOX和JS,用来输入查询的域名和域名类型,第二个页面是用来向万网接口提交的页面,提交后将查询结果分析,并返回状态.其实这样子就够用了,但是原作者传值是用了SESSION的方法进行传值,而我现在需要将查询域名做成AJAX的效果,这样在两个页面之间传送SESSION时会有一点点小麻烦,所以我将代码改了改,将原来的SESSION传值改成了javascript 的POST提交方式.这样以便于我们后面AJAX程序调用.改完后仍然是两个页面,直接将改动后的代码贴出来供大家参考和改进.

    域名查询页面DomainCheck.aspx

以下是DomainCheck.aspx的前台代码,主要是用JS来判断域名的一些合法性,然后就是将用户选择后的域名和域名后辍组织成URL向另一个查询页面DomainPost.aspx提交

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

<!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>域名查询</title>
    <link href="css/style.css" type="text/css" rel="stylesheet" />
    <script src="js/door.js" type="text/javascript"></script>
    <script type="text/javascript">
   
    //   域名查询中用到的判断的JS代码
    function IsChDomain(domainStr)
  {
      var flag = false;
      var compStr = "ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_0123456789";
      var domainLength = domainStr.length;
      for(var i = 0;i < domainLength;i++)
      {
          var temp = domainStr.charCodeAt(i);
          if(temp >= 10000)//含有字符编码大于10000的字符判断为中文,不太严格
          {
               flag=true;
          }
          else
          {
              var temp2 = compStr.indexOf(domainStr.charAt(i));
              if(temp2 == -1)
              {
                  flag = false;
                  break;
              }
          }
      }
  return flag;
  }

function IsEnDomain(domainStr)
  {
      var flag = false;
      var compStr = "ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_0123456789";
      var domainLength = domainStr.length;
      for(var i = 0;i<domainLength;i++)
      {
          if(compStr.indexOf(domainStr.charAt(i)) == -1)
          {
              flag = false;
              break;
          }
          else
          {
               flag = true;
          }
      }
  return flag;
  }
  
  function Trim(domainStr)
  {
      return domainStr.replace(/(^s*)|(s*$)/g, "");
  }

  function checkValue()
  {
      if(document.getElementById("txtDomainName").value=='')
      {
          alert('请输入域名!');
          return false;
      }
      if(document.getElementById("txtDomainName").value.length >= 60)
      {
          alert('域名长度不能超过60个字符!');
          return false;
      }
      for(var i = 0;i < document.getElementById("txtDomainName").value.length;i++)
      {
          if(document.getElementById("txtDomainName").value.charAt(i) == ' ')
          {
              alert('域名中不能含有空格!');
              return false;
              break;
          }
      }
  checkDomainType();
  callServer();
  return true;
  }

  function checkDomainType()
  {
      var domainName = document.getElementById("txtDomainName").value;
      domainName = Trim(domainName);
      if(IsChDomain(domainName))
      {
          setCheckBox(true);
      }
      else if(IsEnDomain(domainName))
      {
          setCheckBox(false);
      }
  }

  function setCheckBox(flag)
  {
      document.getElementById("chkcom").disabled = flag;
      document.getElementById("chknet").disabled = flag;
      document.getElementById("chkcn").disabled = flag;
      document.getElementById("chkbiz").disabled = flag;
      document.getElementById("chktv").disabled = flag;
      document.getElementById("chkcc").disabled = flag;
      document.getElementById("chkorg").disabled = flag;
      document.getElementById("chkorgcn").disabled = flag;
      document.getElementById("chkcomcn").disabled = flag;
      document.getElementById("chknetcn").disabled = flag;
      document.getElementById("chkgovcn").disabled = flag;
      document.getElementById("chkmobi").disabled = flag;
      document.getElementById("chkinfo").disabled = flag;
      document.getElementById("chkcn").disabled = flag;
      document.getElementById("chkchina").disabled = !flag;
      document.getElementById("chkcompany").disabled = !flag;
      document.getElementById("chknetwork").disabled = !flag;
  }

    </script>
   
    <script language="javascript" type="text/javascript">
    var xmlHttp = false;
    try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e2)
            {
                xmlHttp = false;
            }
        }
        if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
        xmlHttp = new XMLHttpRequest();
    }

    function callServer() {
        var Domain = document.getElementById("txtDomainName").value;
      var DomainTyle="";
      if(document.form1.chkcom.checked==true) DomainTyle+=".com";
      if(document.form1.chknet.checked==true) DomainTyle+=".net";
      if(document.form1.chkcn.checked==true) DomainTyle+=".cn";
      if(document.form1.chkbiz.checked==true) DomainTyle+=".biz";
      if(document.form1.chktv.checked==true) DomainTyle+=".tv";
      if(document.form1.chkcc.checked==true) DomainTyle+=".cc";
      if(document.form1.chkorg.checked==true) DomainTyle+=".org";
      if(document.form1.chkorgcn.checked==true) DomainTyle+=".org.cn";
      if(document.form1.chkcomcn.checked==true) DomainTyle+=".com.cn";
      if(document.form1.chknetcn.checked==true) DomainTyle+=".net.cn";
      if(document.form1.chkgovcn.checked==true) DomainTyle+=".gov.cn";
      if(document.form1.chkmobi.checked==true) DomainTyle+=".mobi";
      if(document.form1.chkinfo.checked==true) DomainTyle+=".info";
      if(document.form1.chkchina.checked==true) DomainTyle+=".中国";
      if(document.form1.chkcompany.checked==true) DomainTyle+=".公司";
      if(document.form1.chknetwork.checked==true) DomainTyle+=".网络";
        if ((Domain == null) || (Domain == "")||(DomainTyle=="")) return;
       
        var url = "DomainCheck.aspx?Action=Check&Domain="+Domain+"&DomainTyle="+DomainTyle+"";
        //alert(url);
        xmlHttp.open("GET", url, true);
        xmlHttp.onreadystatechange = updatePage;
        xmlHttp.send(null); 
    }

    function updatePage() {
        if (xmlHttp.readyState < 4) {
            test1.innerHTML="loading...";
        }
        if (xmlHttp.readyState == 4) {
            var response = xmlHttp.responseText;
            test1.innerHTML=response;
        }
    }
</script>
</head>
<body>
        <form runat="server" id="form1">
        <table width="220" height="100%" border="0" cellpadding="0" cellspacing="0" background="images/Rabbit_r54_c14.jpg">
          <tr>
            <td height="26">
            <table width="100%" height="25" border="0" align="left" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                <tr align="center">
                  <td height="25" align="center" class="cz105" id="czl05" style="cursor:pointer;" onMouseOver="csecBoard2(5);">域名查询</td>
                  <td height="25" align="center" class="cz106" id="czl06" style="cursor:pointer;" onMouseOver="csecBoard2(6);">备案查询</td>
                  <td height="25" align="right"><a href="domain.aspx">查询更多>></a></td>
                </tr>
              </table>
              </td>
          </tr>
          <tr>
            <td align="center" valign="top" height="145" style="padding-bottom:2px;">
            <!--域名查询开始-->
              <div style="display: block; text-align:left;" id="cbxz05">
                <div style="width:100%; background-color:White;background:url(images/yu_r5_c2.jpg) no-repeat left; padding-left:50px; overflow:hidden;">   
                <input id="txtDomainName" runat="server" type="text" onchange="checkDomainType()" class="input3" />&nbsp;&nbsp; <asp:Button
                        ID="Button1" runat="server"  Text="" CssClass="button"  OnClientClick="return checkValue()"  />
                </div>
                <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
        <div style="width:228px; background-color:White;">
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chkcom" runat="server" Text=".com" /></div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chknet" runat="server" Text=".net" /></div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chkcn" runat="server"  Text=".cn"/></div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chkcc" runat="server" Text=".cc" /></div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chktv" runat="server" Text=".tv" /></div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chkinfo" runat="server" Text=".info" /></div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chkorg" runat="server" Text=".org" /></div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chkorgcn" runat="server" Text=".org.cn" /></div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chkcomcn" runat="server"  Text=".com.cn"/></div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chknetcn" runat="server"  Text=".net.cn"/></div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chkgovcn" runat="server"  Text=".gov.cn"/> </div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chkbiz" runat="server" Text=".biz" /></div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chkchina" runat="server" Text=".中国" /></div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chkcompany" runat="server"  Text=".公司"/></div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chknetwork" runat="server" Text=".网络" /> </div>
            <div style="width:33%; float:left; text-align:left;"><asp:CheckBox ID="chkmobi" runat="server" Text=".mobi" /> </div>
        </div>
              </div>
              <!--域名查询结束-->
              <div style="display: none; text-align:left;" id="cbxz06">
                <table width="97%" border=0 align="center" cellspacing=0>
                  <tbody>
                    <tr>
                      <td align="left" nowrap>
                      <form id="form3" name="form1" method="post" action="http://www.miibeian.gov.cn/CX/main.jsp" target="_blank">
                        <table width="98%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td height="10">&nbsp;</td>
                          </tr>
                          <tr>
                            <td height="40" align="left"><span class="b">网站域名:
                              <input name="ym" type="text" class="input1" id="ym" size="23" />
                            </span></td>
                          </tr>
                          <tr>
                            <td height="20" align="left">&nbsp;注:不包含&quot;http://&quot;或&quot;www.&quot;</td>
                          </tr>
                          <tr>
                            <td height="40" align="left" style="line-height:30px;"><a href="http://www.miibeian.gov.cn/chaxun/ggcx.jsp" target="_blank">查询更多&gt;&gt;</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                              <input type="submit" name="button" id="button" value="" class="button1" /></td>
                          </tr>
                        </table>
                      </form>
                      </td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </td>
          </tr>
        </table>
        <!----><span id="test1"></span>
        </form>
</body>
</html>

    以上是查询页面,下面是它的后台CS文件

其实什么代码也没有写,因为此页面主要是用来提交之用,我把后台几乎不用写什么代码

using System;
using System.Collections;
using System.Web;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Xml;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;

public partial class DomainCheck : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
}

 

 

    OK,我们再来看看查询页面,此页面主要是向万网的域名查询接口网址提交查询内容,将返回结果组织成我们想要的格式来返回.代码主要如下:

DomainPost.aspx 的前台代码

  

嘿嘿,其实什么代码都没有写,主要功能全是后台CS代码中完成的,前台只是显示作用

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

再看看它的后台代码

以下代码主要是用来完成远程提交的,

using System;
using System.Collections;
using System.Configuration;
using System.Data;
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.Net;
using System.Collections.Generic;
using System.Xml;
using System.IO;

public partial class DomainPost : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        IList<string> domainList = new List<string>();//保存域名名称和后缀
        if ((Request["Action"] == "Check") && (Request["Domain"] != "") && (Request["DomainTyle"] != ""))
        {
            string domainName = Request["Domain"];

            domainList.Add(domainName);//List<string>第一元素保存域名名称,其他元素为域名后缀
            string[] ExtArry = Request["DomainTyle"].Split('.');
            for (int i = 1; i < ExtArry.Length; i++)
            {
                domainList.Add("."+ExtArry[i]);
            }
        }

        //显示域名查询情况:
        if (domainList.Count > 1)
        {
            string dm = domainList[0];
            string dname;
            Label lbl;
            for (int i = 1; i < domainList.Count; i++)
            {
                dname = dm + domainList[i];
                if (IsReg(dname))
                {
                    Response.Write("<div style='width:200px;clear:both;'><div style='width:120px;float:left'>" + dname + "</div><div style='width:80px;color:green;float:left'>&nbsp;&nbsp;<a href='DomainReg.aspx' target='_blank' style='color:green;text-decoration:none;'>可以注册</a></div></div>");
                }
                else
                {
                    Response.Write("<div style='width:200px;clear:both;'><div style='width:120px;float:left'>" + dname + "</div><div style='width:80px;color:green;float:left'>&nbsp;&nbsp;<a href='DomainReg.aspx' target='_blank' style='color:red;text-decoration:none;'>已被注册</a></div></div>");
                }
            }
        }
    }

 

    //判断域名是否被注册(方法):
    ///  Blog:http://xianfen.net

    public static bool IsReg(string domainName)
    {
        bool flag = false;
        string dm = HttpContext.Current.Server.UrlEncode(domainName);
        try
        {
            WebClient wc = new WebClient();
            string xmlstr = wc.DownloadString("http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=" + dm);
            StringReader sr = new StringReader(xmlstr);
            XmlTextReader xr = new XmlTextReader(sr);
            while (xr.Read())
            {
                if (xr.IsStartElement("original"))
                {
                    xr.Read();
                    if (xr.Value.Substring(0, 3) == "210")
                    {
                        flag = true;
                        break;
                    }
                    else
                    {
                        flag = false;
                        break;
                    }
                }
            }
            return flag;
        }
        catch
        {
            return false;
        }
    }
}

原理基本上是这样子的,沿用了原作者的写法,不同的是,原作者从SESSION中取值,而这里用REQUEST来取值,这样有利于后期的调用.查询方法为

http://qhit.me/Domainpost.aspx?action=Check&domain=qhwins&DomainTyle=.com.cn.net 这样就可以查询了,方便后期在AJAX页面中提交.

文章没有多少水平,仅写出来供大家参考,其中原作者查询万网接口的方法有待改进.这里先直接用上了,要是我有时间再更新吧.


上一篇:ASP.NET(c#)实现中英文域名查询
下一篇:.NET对IIS的控制
评论列表
正在加载评论……
  
评论   
呢  称:
验证码: 若看不清请点击更换!
内  容:
 
 
  在线洽谈咨询:
点击这里,在线洽谈   点击这里,在线洽谈   点击这里,在线洽谈
与我交谈  与我交谈 与我交谈
乘车路线    汇款方式   加盟合作  人才招聘  
公司地址:青海省西宁市西关大街73号(三二四部队招行所四楼)     青ICP备13000578号-1 公安机关备案号:63010402000123    
QQ:147399120    mail:lostlove000@163.com    电话: 13897410341    邮编:810000
© Copyright( 2008-2009) QhWins.Com All Rights Reserved    版权所有:西宁威势电子信息服务有限公司 未经书面制授权,请勿随意转载!
业务:青海网站制做青海网站建设青海网页设计西宁网站制做西宁网站建设青海域名注册青海网络推广青海网站推广青海空间租用青海软件开发网站安全网络安全