如何检查哪个用户登录主页Lable文本 [英] How to Check which user is login on masterpage Lable text

查看:73
本文介绍了如何检查哪个用户登录主页Lable文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Developers,



我想知道我的网站主页,哪个用户登录了他的帐户。如果有人登录,那么他的用户名将显示在他的系统中我的网站主页上。如果没有人登录,则会显示欢迎客人。



请给我解决方案,

我已经尝试过它用

1.使用会话



if(Session [client_username] == null)

{

lbl_user.Text =欢迎客人;

}

其他

{

lbl_user.Text = username.ToString();



}



使用会话,它不工作,它总是显示欢迎客人



2根据IsLogin状态字段选择表格数据库表。



DataSet ds = c_client_login.status(Session [client_username]。ToString(),1);

if(ds.Tables [0] .Rows [ 0] [IsLogin]。ToString()!=1;)

{



lbl_user.Text =" Welcome来宾;



// txt _pric.Text = ds.Tables [0] .Rows [0] [" total_price"]。ToString()+" / - " ;;

}

否则

{

lbl_user.Text = Session [" client_username"]。ToString();

//txt_pric.Text =" 0 / - " ;;

}



2方式,显示和错误对象引用未设置为实例







请给我一个完美的解决方案

解决方案

< blockquote>您只需要设置会话变量。但是你要在set Session [client_username] = someVariable中记录它们;然后你就可以在任何需要的地方使用它。


只需在登录期间输入userID到会话中就可以了.. :)





会话[  user ] =  5 ; 





你可以得到任何申请到的地方它不会过期像



 lblSession.Text =会话[  user]。toString(); 





像这样设置会话超时



< configuration> 
< system.web>
< sessionState timeout = 20 > < / sessionState >
< / system.web >
< / configuration >


Hello Developers,

I want to know on my website Home page, which user is login in his account. If anyone will be login, then his Username will be displayed on my website home page in his system. and if no one is login, then "Welcome Guest" will be displayed.

Please give me solution for this,
I already try it with
1. By use of session

if (Session["client_username"] == null)
{
lbl_user.Text = "Welcome Guest";
}
else
{
lbl_user.Text = username.ToString();

}

use of session, it is not working, it always show "Welcome Guest"

2 select form database table according to field of "IsLogin" status.

DataSet ds = c_client_login.status(Session["client_username"].ToString(), 1);
if (ds.Tables[0].Rows[0]["IsLogin"].ToString() != "1";)
{

lbl_user.Text = "Welcome Guest";

//txt_pric.Text = ds.Tables[0].Rows[0]["total_price"].ToString() + "/-";
}
else
{
lbl_user.Text = Session["client_username"].ToString();
//txt_pric.Text = "0/-";
}

2 way, it display and error of" Object reference not set to an instance



please give me a perfect solution

解决方案

You just need to set the session variable. However you are logging them in set Session["client_username"] = someVariable; Then you can use it wherever you need it.


Just enter userID in to session during login like this.. :)


Session["user"]= 5;



You can got it Any where in application till it will not expired like

lblSession.Text=Session["user"].toString();



Set session timeout like this

<configuration>
  <system.web>
     <sessionState timeout="20"></sessionState>
  </system.web>
</configuration>


这篇关于如何检查哪个用户登录主页Lable文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆