我在一个login页面中打算用session保存登录成功的用户的用户名,但是提示未定义。但是在default.aspx中用来读取和显示的语句就没有这样的提示。请问各位这个要怎么解决呢?
代码大概是这样的://login.aspx.cs
private bool SiteLevelCustomAuthenticationMethod(string UserName,string Password)
{
bool boolReturnValue =false;
// Insert code that implements a site-specific custom
// authentication method here.
// This example implementation always returns false.
string strConnection = "server=WIN-VM5GVPGG2R3;database=laborage;integrated security=true;";
SqlConnection Connection =new SqlConnection(strConnection);
String strSQL = "Select * From ADMINISTRATOR";
SqlCommand command =new SqlCommand(strSQL, Connection);
SqlDataReader Dr;
Connection.Open();
Dr=command.ExecuteReader();
while(Dr.Read())
{
if((UserName == Dr["ID"].ToString()) & (Password == Dr["PWD"].ToString()))
{
boolReturnValue =true;
Session("admin") = Dr["ADNAME"];
}
Dr.Close();
return boolReturnValue;
}
return false;
}执行的时候提示了错误
default.aspx.cs中有写这样的(我是把这个显示用户信息的代码写在一个master文件里然后套到主页上面的) if (Session["admin"] == null) Response.Redirect("~/login.aspx");这个地方没有报错……这到底是怎么回事呢?请各位帮帮忙~~~
代码大概是这样的://login.aspx.cs
private bool SiteLevelCustomAuthenticationMethod(string UserName,string Password)
{
bool boolReturnValue =false;
// Insert code that implements a site-specific custom
// authentication method here.
// This example implementation always returns false.
string strConnection = "server=WIN-VM5GVPGG2R3;database=laborage;integrated security=true;";
SqlConnection Connection =new SqlConnection(strConnection);
String strSQL = "Select * From ADMINISTRATOR";
SqlCommand command =new SqlCommand(strSQL, Connection);
SqlDataReader Dr;
Connection.Open();
Dr=command.ExecuteReader();
while(Dr.Read())
{
if((UserName == Dr["ID"].ToString()) & (Password == Dr["PWD"].ToString()))
{
boolReturnValue =true;
Session("admin") = Dr["ADNAME"];
}
Dr.Close();
return boolReturnValue;
}
return false;
}执行的时候提示了错误
default.aspx.cs中有写这样的(我是把这个显示用户信息的代码写在一个master文件里然后套到主页上面的) if (Session["admin"] == null) Response.Redirect("~/login.aspx");这个地方没有报错……这到底是怎么回事呢?请各位帮帮忙~~~
如果其他地方有少个分号什么的 有时也会在session下面打横线
Session["admin"] = Dr["ADNAME"];
這裡括號啊!Session["admin"]= Dr["ADNAME"];
顶楼上的Session("admin") = Dr["ADNAME"];用中括号!