在asp.net中将userid保存在会话中 [英] save userid in session in asp.net

查看:98
本文介绍了在asp.net中将userid保存在会话中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户表中有一个用户ID,它是主键,我想在会话中保存此用户ID ..

当用户上传documnet时,他/她的用户ID保存在文档表的documnet表中是用户ID列..



我是怎么做到的?/



这是dcoument表的图像它显示我0用户ID



http://i43.tinypic.com/300a82b.png [ ^ ]





这里是login.aspx.cs的代码



there is a userid in user table and it is primary key and i want to save this userid in session ..
when user upload documnet his/her userid save in documnet table in document table there is userid column ..

how i done this ?/

this is the image of dcoument table it shows me 0 userid

http://i43.tinypic.com/300a82b.png[^]


and here is the code of login.aspx.cs

protected void Btn_Login_Click(object sender, EventArgs e)
       {
          try
           {
            int users = aa.SignIn(txt_username.Value, txt_pass.Value);
               int user_id;
               if (Session["UserID"] != null)
               {
                   user_id = Convert.ToInt32(Session["UserID"].ToString());
               }
                  if (users == 1)
                   {
                       Session["Login2"] = 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["Login2"] = txt_username.Value;

                       Session["UserTypeID"] = users;

                       Response.Redirect("upload.aspx");
                   }
               }
           catch
           {
               Label8.Text = "Incorrect User Name or Password";
           }
       }
   }
   }



plzz help


plzz help

推荐答案

plz在文档表中创建与用户表相同的UserId字段。当你添加文件而不是在文档表中插入用户ID(字段中的用户ID)。和用户ID时,你将从会话变量中输入,保留用户ID 。 thankyou
plz Create UserId field in document table same as user table .and when u add file than insert userid within Document table (userid in field).and userid you will takes as input from session variable which keeps userid. thankyou


plz写

if(Session [userid]!= null)//回发之前

{

int userId = Convert.ToInt32(Session [UserID]); //回发之前



if(!IsPostBack)

{



}

}

else

{

respone.redirect(login.aspx);

}
plz write
if (Session["userid"] != null)//before postback
{
int userId = Convert.ToInt32(Session["UserID"]);//before postback

if (!IsPostBack)
{

}
}
else
{
respone.redirect("login.aspx");
}


这篇关于在asp.net中将userid保存在会话中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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