//********************************************
//
//            类里的代码
//
//********************************************using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Data;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using CTCMS.Function;
using CTCMS.DBContrl;namespace CTCMS.Manage
{
/// <summary>
/// 后台相关操作
/// </summary>
public class Manage_Common : System.Web.UI.Page
{
    private CTCMS.DBContrl.Data Data=new CTCMS.DBContrl.Data();
private string masterName="";
private string masterPass="";
public HttpCookie Cookie=HttpContext.Current.Request.Cookies["CTCMSManage"]; /// <summary>
/// Cookie路径
/// </summary>
public string CookiePath
{
get
{
string str; str = HttpContext.Current.Request.Url.AbsolutePath;
return str.Substring(0, str.LastIndexOf("/") + 1);
}
}
/// <summary>
/// 设置MasterName属性
/// </summary>
public string MasterName
{
get
{
return masterName.Trim();
}
set
{
masterName=value.Trim();
}
}
/// <summary>
/// 设置Pass属性
/// </summary>
public string MasterPass
{
get
{
return masterPass.Trim();
}
set 
{
masterPass=value.Trim();
}
}
public Manage_Common()
{
if (Cookie!=null)
{
MasterName=CtCms.ConvertValue(Cookie["AdminName"]);
MasterPass=CtCms.ConvertValue(Cookie["AdminPass"]);
}
if(MasterName.ToLower().IndexOf("ctcms")!=-1 || MasterPass.ToLower().IndexOf("ctcms")!=1)
{
MasterName="";
MasterPass="";
}
} public void CheckIsLogin()
{
CheckIsLogin(true);
}
public void CheckIsLogin(bool Redirect)
{
bool flag=true;
DataTable dataTable=new DataTable();

if(MasterName=="" && MasterPass=="")
{
flag=false;
}
if (flag)
{
string sql=string.Concat(new string[]{"Select * From CTcms_Master Where Master_Name=\'"
 ,MasterName,"\' And Master_Pass=\'",MasterPass,"\' And State=,1,"});
dataTable=Data.DataSet(sql,"CTcms_Master").Tables["CTcms_Master"];
if (dataTable.Rows.Count==0)
{
flag=false;
}
else if(dataTable.Rows[0]["Master_Pass"].ToString()!=MasterPass || dataTable.Rows[0]["Master_Name"].ToString()!=MasterName)
{
flag=false;
}
else
{
MasterName = dataTable.Rows[0]["Master_Name"].ToString();
MasterPass = dataTable.Rows[0]["Master_Pass"].ToString();
}
}
if (Redirect && !flag)
{
HttpCookie httpcookie=new HttpCookie("CTCMSManage");
httpcookie["AdminName"]="";
httpcookie["AdminPass"]="";
httpcookie.Expires=DateTime.Now.AddHours(-1.0);
HttpContext.Current.Response.Cookies.Add(httpcookie);
base.Server.Transfer("Login.Aspx");
}
}
} }
//*****************************************
//
//             Aspx里引用的代码
//
//*****************************************
Manage=new Manage_Common();
Manage.CheckIsLogin();这样做验证死活通过不了,原因是MasterName到aspx就丢了..怎么办呢?

解决方案 »

  1.   

    把值赋给ViewState["MasterName"],之后都使用ViewState["MasterName"]做变量!
      

  2.   

    是不是postback时丢了?放到Session里吧.
      

  3.   

    诶!这个我倒没注意...postback,
    按我的代码从根本上看没有问题吧?
      

  4.   

    问题已经解决.晕
    if(MasterName.ToLower().IndexOf("ctcms")!=-1 || MasterPass.ToLower().IndexOf("ctcms")!=1)问题出在MasterPass.ToLower().IndexOf("ctcms")!=1)
    谢谢楼上的各位.