/*
* 项目名称:N3software
* 创建日期:2006-06-27
* 版 本 号:1.0.0.0
* 技术支持:http://www.n3software.com
* 电子邮箱:[email protected]
*/using System;
using System.Web;namespace N3software.Class
{
/// <summary>
/// RegValidate 的摘要说明。
/// </summary>
public class RegValidate
{
protected int m_nMaxRegWeb = 100, m_nHasRegWeb = 0;
protected string [] m_aryRegWeb;
public RegValidate()
{
// 网站域名注册信息
m_aryRegWeb = new string[m_nMaxRegWeb];
AddRegWeb( "127.*.*.*|2006-06-10|2008-06-10" );
AddRegWeb( "192.*.*.*|2006-06-10|2008-06-10" );
AddRegWeb( "10.*.*.*|2006-06-10|2008-06-10" );
AddRegWeb( "172.*.*.*|2006-06-10|2008-06-10" );
AddRegWeb( "localhost|2006-06-10|2008-06-10" );
AddRegWeb( "netfree.meibu.com|2006-06-10|2008-06-10" );
}public string Check()
{
string strResult = "此访问地址注册无效";
string strWebName = "", strCurrentDate = "", strTemp = "";
string strStartDate = "", strEndDate = "";
string [] aryTemp;
int i = 0;strWebName = GetWebName().ToLower();
strCurrentDate = GetCurrentDate();// 内网IP地址检测
strTemp = strWebName.Substring( 0, 3 );
if ( strTemp == "127" || strTemp == "192" || strTemp == "10." || strTemp == "162" )
{
for ( i=0; i<m_nHasRegWeb; i++ )
{
if ( m_aryRegWeb[i].Substring( 0, 3 ) == strTemp )
{
strTemp = m_aryRegWeb[i];
strResult = "OK";
break;
}
}
}// 域名检测
for ( i=0; i<m_nHasRegWeb; i++ )
{
aryTemp = m_aryRegWeb[i].Split( '|' );
if ( aryTemp[0] == strWebName )
{
strTemp = m_aryRegWeb[i];
strResult = "OK";
break;
}
}// 使用超时检测
if ( strResult == "OK" )
{
aryTemp = strTemp.Split( '|' );
strResult = "注册日期使用超时"; // 重设为失败值
strStartDate = aryTemp[1].ToString(); // 使用开始日期
strEndDate = aryTemp[2].ToString(); // 使用结束日期
if ( strCurrentDate.CompareTo( strStartDate ) >= 0 && strCurrentDate.CompareTo( strEndDate ) <= 0 )
{
strResult = "OK";
}
}// 最终结果检测
if ( strResult != "OK" )
{
strResult = string.Format( " \"{0}\" {1}, 请联系服务供应商 (软件项目开发网 http://www.n3software.com)", strWebName, strResult );
}return strResult;
}private bool AddRegWeb(string strRegWeb)
{
bool bResult = true;
if ( m_nHasRegWeb < m_nMaxRegWeb )
{
m_aryRegWeb[m_nHasRegWeb++] = strRegWeb;
}
else
{
bResult = false;
}return bResult;
}private string GetWebName()
{
string strResult = "", strTemp = "", strTemp2 = "";
HttpRequest Request = HttpContext.Current.Request;
strTemp = Request.Url.ToString();
for ( int i=7; i<strTemp.Length; i++ )
{
strTemp2 = strTemp.Substring( i, 1 );
if ( strTemp2 != "/" )
{
strResult += strTemp2;
}
else
{
break;
}
}
return strResult;
}private string GetCurrentDate()
{
string strResult = "";
strResult = DateTime.Now.ToString( "yyyy-MM-dd" );
return strResult;
}
}
}
调用例子
比如在数据库访问接口加入 RegValidate rvRegValidate = new RegValidate();
string strTemp = rvRegValidate.Check();
if ( strTemp != "OK" )
{
throw new Exception( strTemp );
}
* 项目名称:N3software
* 创建日期:2006-06-27
* 版 本 号:1.0.0.0
* 技术支持:http://www.n3software.com
* 电子邮箱:[email protected]
*/using System;
using System.Web;namespace N3software.Class
{
/// <summary>
/// RegValidate 的摘要说明。
/// </summary>
public class RegValidate
{
protected int m_nMaxRegWeb = 100, m_nHasRegWeb = 0;
protected string [] m_aryRegWeb;
public RegValidate()
{
// 网站域名注册信息
m_aryRegWeb = new string[m_nMaxRegWeb];
AddRegWeb( "127.*.*.*|2006-06-10|2008-06-10" );
AddRegWeb( "192.*.*.*|2006-06-10|2008-06-10" );
AddRegWeb( "10.*.*.*|2006-06-10|2008-06-10" );
AddRegWeb( "172.*.*.*|2006-06-10|2008-06-10" );
AddRegWeb( "localhost|2006-06-10|2008-06-10" );
AddRegWeb( "netfree.meibu.com|2006-06-10|2008-06-10" );
}public string Check()
{
string strResult = "此访问地址注册无效";
string strWebName = "", strCurrentDate = "", strTemp = "";
string strStartDate = "", strEndDate = "";
string [] aryTemp;
int i = 0;strWebName = GetWebName().ToLower();
strCurrentDate = GetCurrentDate();// 内网IP地址检测
strTemp = strWebName.Substring( 0, 3 );
if ( strTemp == "127" || strTemp == "192" || strTemp == "10." || strTemp == "162" )
{
for ( i=0; i<m_nHasRegWeb; i++ )
{
if ( m_aryRegWeb[i].Substring( 0, 3 ) == strTemp )
{
strTemp = m_aryRegWeb[i];
strResult = "OK";
break;
}
}
}// 域名检测
for ( i=0; i<m_nHasRegWeb; i++ )
{
aryTemp = m_aryRegWeb[i].Split( '|' );
if ( aryTemp[0] == strWebName )
{
strTemp = m_aryRegWeb[i];
strResult = "OK";
break;
}
}// 使用超时检测
if ( strResult == "OK" )
{
aryTemp = strTemp.Split( '|' );
strResult = "注册日期使用超时"; // 重设为失败值
strStartDate = aryTemp[1].ToString(); // 使用开始日期
strEndDate = aryTemp[2].ToString(); // 使用结束日期
if ( strCurrentDate.CompareTo( strStartDate ) >= 0 && strCurrentDate.CompareTo( strEndDate ) <= 0 )
{
strResult = "OK";
}
}// 最终结果检测
if ( strResult != "OK" )
{
strResult = string.Format( " \"{0}\" {1}, 请联系服务供应商 (软件项目开发网 http://www.n3software.com)", strWebName, strResult );
}return strResult;
}private bool AddRegWeb(string strRegWeb)
{
bool bResult = true;
if ( m_nHasRegWeb < m_nMaxRegWeb )
{
m_aryRegWeb[m_nHasRegWeb++] = strRegWeb;
}
else
{
bResult = false;
}return bResult;
}private string GetWebName()
{
string strResult = "", strTemp = "", strTemp2 = "";
HttpRequest Request = HttpContext.Current.Request;
strTemp = Request.Url.ToString();
for ( int i=7; i<strTemp.Length; i++ )
{
strTemp2 = strTemp.Substring( i, 1 );
if ( strTemp2 != "/" )
{
strResult += strTemp2;
}
else
{
break;
}
}
return strResult;
}private string GetCurrentDate()
{
string strResult = "";
strResult = DateTime.Now.ToString( "yyyy-MM-dd" );
return strResult;
}
}
}
调用例子
比如在数据库访问接口加入 RegValidate rvRegValidate = new RegValidate();
string strTemp = rvRegValidate.Check();
if ( strTemp != "OK" )
{
throw new Exception( strTemp );
}
解决方案 »
- 对于微软SocketAsyncEventArgs例子的疑问以及异步通信问题
- C# 中如何把PictureBox 的图片添加到 ImageList ?
- 急~~~求条sql语句
- 异常详细信息: System.Data.SqlClient.SqlException: 过程或函数 'spCustomersRegister' 需要参数 '@Name',但未提供该参数。
- 怎么样对字符串中与数据库中相符字符进行操作
- 关于类的析构函数
- 求教:写下载和上传文件代码的时候不能识别服务器端的中文文件目录和文件名?如何解决
- 来帮忙看看吧--windows窗体程序中datagrid的问题
- 只要能帮我,一切都是好人,我一定会给分的。
- 谁能提供个Global.asax应用的例子,最好有代码。
- 说了又说——每个人都会遇到的问题——数据库连接优化问题(涉及到设计模式)
- DataGridViewComboBoxCell 中选中一个Item可以触发什么事件
自己顶一个