在asp.net中保存用户标识 [英] save a userid in asp.net
问题描述
嘿
如何在会话中保存用户ID
就像我在这个表中有一个用户表有一个列userid,名称..
并且这个列中有另一个documnet表是docid,docname,file,userid
当usersignup将his.her信息保存在用户表中时喜欢这个
用户名用户名
1 abc
用户ID是主键
然后当这个用户上传documnet时
docid doname file userid
1 def math.docx null
那么我想在这样的文档中使用userid
docid docname文件用户ID
1 def math.docx 1
然后怎么做以及如何在会话中保存用户ID
这是lgin代码并且在此我在会话中保存用户名
protected void Btn_Login_Click( object sender,EventArgs e)
{
try
{
int users = aa.SignIn(txt_username.Value,txt_pass.Value);
if (users == 1 )
{
// Session [UserID] = aa.SignIn (txt_username.Value,txt_pass.Value);
会话[ UserID ] = txt_username.Value;
会话[ UserTypeID] = users;
Response.Redirect( AdminOp.aspx);
}
else if (users = = 2 )
{
// Session [UserID] = aa.SignIn(txt_username.Value,txt_pass.Value);
会话[ UserID] = txt_username.Value;
会话[ UserTypeID] = users;
Response.Redirect( leave.aspx);
}
}
catch
{
Label8.Text = 用户名或密码不正确;
}
Int user_id;
if (会话[ UserID]!= null )
{
// 从会话中检索UserName
user_id = int .Parse(Session [ UserID]);
}
其他
{
// < span class =code-comment>执行其他操作
}
现在将user_id分配给包含文档的列
嘿那里,
这是一个建议:
你可以用你的SignIn(txt_username.Value,txt_pass.Value)
返回DataTable中Table的用户
记录登录成功。
这样你就可以同时获得UserTypeID
和UserID
与当前用户相关。
因此,您可以将这两个字段保存在Session
对象中,假设dt
是返回的DataTable,例如
会话[ UserID] = dt.Rows [ 0 ] [ UserID]。ToString();
及时如果您想在保存文档记录时使用此UserID,可以执行此操作以从Session获取UserID。
if (会话[ UserID]!= null )
{
long UserID = Convert.ToInt64(Session [ UserID]。ToString());
}
希望它有所帮助。
Azee。 ..
hey
how to save a userid in session
like i have a user table in this table there is a column userid,name..
and there is another table which is documnet in this columns are docid,docname,file,userid
when usersignup the his.her info is save in user table like this
userid username
1 abc
userid is primary key
then when this same user upload documnet like
docid doname file userid
1 def math.docx null
then i want userid in document like this
docid docname file userid
1 def math.docx 1
then how done this and how save userid in session
this is the lgin code and in this i save username in session
protected void Btn_Login_Click(object sender, EventArgs e)
{
try
{
int users = aa.SignIn(txt_username.Value, txt_pass.Value);
if (users == 1)
{
//Session["UserID"] = aa.SignIn(txt_username.Value, txt_pass.Value);
Session["UserID"] = txt_username.Value;
Session["UserTypeID"] = users;
Response.Redirect("AdminOp.aspx");
}
else if (users == 2)
{
//Session["UserID"] = aa.SignIn(txt_username.Value, txt_pass.Value);
Session["UserID"] = txt_username.Value;
Session["UserTypeID"] = users;
Response.Redirect("leave.aspx");
}
}
catch
{
Label8.Text= "Incorrect User Name or Password";
}
Int user_id; if (Session["UserID"] != null) { //Retrieving UserName from Session user_id = int.Parse(Session["UserID"]); } else { //Do Something else }
Now assign the user_id to column of that contains documents
Hey there,
Here is a suggestion:
You can use yourSignIn(txt_username.Value, txt_pass.Value)
to return theUser
record from Table in a DataTable if the login is successful.
This way you,ll be able to get bothUserTypeID
andUserID
related to the current user.
Hence, you can save these two fields in theSession
object, supposedt
is the returned DataTable e.g.
Session["UserID"] = dt.Rows[0]["UserID"].ToString();
and when you want to use this UserID at the time of saving document records, you can do this to get the UserID from Session.
if(Session["UserID"] != null) { long UserID = Convert.ToInt64(Session["UserID"].ToString()); }
Hope it helps.
Azee...
这篇关于在asp.net中保存用户标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!