110,533
社区成员
发帖
与我相关
我的任务
分享
public class MyUser
{
//先获取登陆用户名
private static string userid()
{
string userid;
IPrincipal p = HttpContext.Current.User;
userid = p.Identity.Name.ToString();
return userid;
}
//获取登陆用户对应的会员名称
private static string username()
{
string Name;
if (HttpContext.Current.Session["Name"] != null)
Name = HttpContext.Current.Session["Name"].ToString();
else
{
string id = userid();
SqlServerDataBase db = new SqlServerDataBase();
Name = Convert.ToString(db.GetTier("select Users_Qtname from Fs_Users where Users_id='" + id + "'", null));//获取会员名称
HttpContext.Current.Session["Name"] = Name;//储存到Session中
}
return Name;
}
//声明一个属性,全部调用
/// <summary>
/// 会员名
/// </summary>
public static string UserName
{
get
{
return username();
}
}
}
//全站调用
MyUser.UserName