【发布时间】:2012-08-30 06:47:18
【问题描述】:
我正在使用 c#,在 vs 2008 框架 3.5 中,我需要保存用户名以及何时保存 用户登录,它显示他/她的名字和姓氏,此时可以保存它,并且 这就是我想要的,但需要向用户展示他/她的用户名而不是他/她的用户名 姓。这是我的代码,在此先感谢。
//code in the login
ClPersona login = new ClPersona();
bool isAuthenticated = login.sqlLogin1((txtUsuario.Text), (txtPassword.Text));
if (isAuthenticated)
{
Session["sesionicontrol"] = login.NombreUsuario;
Response.Redirect("../MENU/menu1.aspx");
}
//code in the form where shows the username but I want the first and last name
public partial class menu2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblNombreUsuario.Text = (string)Session["sesionicontrol"];
if (!IsPostBack)
//ClPersona class
public Boolean sqlLogin1(string nombreUsuario, string password)
{
string stSql = "select * from usuarios where usuario='" + nombreUsuario + "' and
pass='" + password + "'and id_rol='1'";
Bd miBd = new Bd();
DataTable dt = miBd.sqlSelect(stSql);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
//return ds;
if (dt.Rows.Count > 0)
{
return true;
}
else
{
return false;
}
}
【问题讨论】:
-
login对象是否提供对属性的访问以检索可以存储在会话中的名字和姓氏? -
@mellamokb 不,问题是我需要将用户名保存在我的数据库中,但用户必须看到他/她的名字和姓氏而不是他/她的用户名,提前谢谢跨度>
-
请显示 sqlLogin1 方法和 ClPersona 类
标签: c# session session-variables