如何获取当前记录的用户ID? [英] How Can I Get Current Logged Userid ?

查看:228
本文介绍了如何获取当前记录的用户ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此方法获取当前登录用户的用户名:

I get username of current logged user with this method:

User.Identity.Name





怎么能我得到当前登录的userId?

谢谢!



how can i get current logged userId ?
Thanks!

推荐答案

首先将数据库中的用户ID读入某个DataTable,而不是将用户ID分配给另一个标签......

First read user id from your database into some DataTable, than assign the user id to an other label...
Label2.Text = MyDataTable.Rows[0]["user_id"]


No..

You have to read it from database and the use like this


 lblUserID.Text = dt.Rows[0]["user_id"]


成功登录后,在Session中存储所需数据这是在您重定向到新页面之前



When you are successfully logged in then store required data in Session like this before you redirect to new page

Session["FullName"]= //from data
Session[UserId]= //from data

Response.Redirect("NewPage.aspx");







在新页面或任何其他页面,您可以获得此会话






In newpage or any other page you can get this session back

if(Session["FullName"]!=null)
{
    string name= Session["FullName"].ToString();
    int UserID= Convert.ToInt32(Session["UserId"].ToString());
}


这篇关于如何获取当前记录的用户ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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