在ASP中使用swagger作為解釋和測試頁面是非常好的,ASP在界面上已經(jīng)有了很大的改進(jìn),那么asp.net實(shí)現(xiàn)中英文多域名檢測的方法有那些呢?下面錯(cuò)新技術(shù)頻道小編帶你了解吧!
第一步:在前臺(tái)頁面中寫入js代碼和相關(guān)控件
/****寫入js代碼****/<%-- 域名檢測 --%>/***寫入相關(guān)控件***///用于顯示查詢的結(jié)果//
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
第二步:在后臺(tái)頁面中寫入方法
using System;using System.Collections;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;using System.Text; //(需要引入的類文件命名空間)using System.Net.Sockets; //(需要引入的類文件命名空間)using System.Text.RegularExpressions; //(需要引入的類文件命名空間)using System.Collections.Generic; //(需要引入的類文件命名空間)using System.Data.Common; //(需要引入的類文件命名空間)using System.Xml; //(需要引入的類文件命名空間)using System.IO; //(需要引入的類文件命名空間)using Microsoft.SqlServer.Server; //(需要引入的類文件命名空間)using System.Net; //(需要引入的類文件命名空間)//判斷是否為中文域名(方法)public static bool IsHasCHZN(string domainName){ Regex RegCHZN = new Regex("[一-龥]"); Match m = RegCHZN.Match(domainName); return m.Success;}//判斷域名是否被注冊(方法)public static bool IsReg(string domainName){ bool flag = false; string dm = HttpContext.Current.Server.UrlEncode(domainName); try { //判斷方法非常多,如打開遠(yuǎn)程文件再處理字符串等等,這里用的方法效率不是很高 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; }}//按鈕事件中protected void imgBtnCheck_Click(object sender, ImageClickEventArgs e){ string txtYM = this.txtYMname.Text.Trim(); if (txtYM == "") { ScriptManager.RegisterStartupScript(this, this.GetType(), "sc", "alert('對(duì)不起,域名不能為空!');", true); } else { string domainName = this.txtYMname.Text.Trim(); IList domainList = new List();//保存域名名稱和后綴domainList.Add(domainName);//List第一元素保存域名名稱,其他元素為域名后綴 //判斷是否為中文域名 if (IsHasCHZN(domainName)) { if (chkchina.Checked) domainList.Add(chkchina.Text);if (chkcompany.Checked) domainList.Add(chkcompany.Text);if (chknetwork.Checked) domainList.Add(chknetwork.Text); } else { if (chkcom.Checked) domainList.Add(chkcom.Text); if (chknet.Checked) domainList.Add(chknet.Text); if (chkorg.Checked) domainList.Add(chkorg.Text); if (chkorgcn.Checked) domainList.Add(chkorgcn.Text); if (chkcn.Checked) domainList.Add(chkcn.Text); if (chkcomcn.Checked) domainList.Add(chkcomcn.Text); if (chknetcn.Checked) domainList.Add(chknetcn.Text); if (chkinfo.Checked) domainList.Add(chkinfo.Text); if (chkcouk.Checked) domainList.Add(chkcouk.Text); if (chkbiz.Checked) domainList.Add(chkbiz.Text); if (chkcc.Checked) domainList.Add(chkcc.Text); if (chktv.Checked) domainList.Add(chktv.Text); if (chkorguk.Checked) domainList.Add(chkorguk.Text); if (chkus.Checked) domainList.Add(chkus.Text); if (chkmeuk.Checked) domainList.Add(chkmeuk.Text); if (chkltduk.Checked) domainList.Add(chkltduk.Text); if (chkin.Checked) domainList.Add(chkin.Text); } Session["localpnlDomainName"] = domainList;//將首頁查詢的域名結(jié)果顯示出來 if (Session["localpnlDomainName"] != null) { IList il = (IList)Session["localpnlDomainName"]; if (il.Count > 1) { string dm = il[0]; string dname; Label lbl;for (int i = 1; i < il.Count; i++) { dname = dm + il[i]; if (IsReg(dname)) { lbl = new Label(); lbl.ID = "lbl" + i.ToString(); lbl.Text = string.Format("{0}????可以注冊!
", dm + il[i]); indexpnlDomainName.Controls.Add(lbl);} else { lbl = new Label(); lbl.ID = "lbl" + i.ToString(); lbl.Text = string.Format("{1}????已被注冊!????[查看]
", dm + il[i], dm + il[i], Server.UrlEncode(dm + il[i])); indexpnlDomainName.Controls.Add(lbl); } } } }}} 上面就是asp.net實(shí)現(xiàn)中英文多域名檢測的方法介紹,如果你是新手操作,那么在學(xué)習(xí)的時(shí)候要多多注意哦,關(guān)注錯(cuò)新技術(shù)頻道可以了解更多專業(yè)的知識(shí)。新聞熱點(diǎn)
疑難解答
圖片精選