存储和获取会话 [英] store and fetch session

查看:52
本文介绍了存储和获取会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用asp.net。我想使用来自Webform1(登录页面)的会话在Webform2(欢迎页面)上显示我的姓名和地址。应该获取名称和地址并将其存储在会话中然后显示。就像我们输入用户名和密码一样,我们在重定向页面上获得所有的pernosal数据。

请帮助我。

Hi,
I am using asp.net. I want to show my name and address on Webform2(Welcome Page) using session from Webform1 (Login Page).Name and address should be fetched and stored in session then show . Just like we put username and password and we get all pernosal data on our redirected page.
Please help me.

推荐答案

创建会话登录页面:



Create session in Log in Page:

Session("userName") = txtUser.Text
Session("userPassword") = txtPassword.Text





在欢迎页面中,您可以访问此会话变量:





In welcome page you can access this session variables as :

Dim currentUser As String = Session("userName")
Dim userPassword As String = Session("userPassword")





您可以参考此链接 http://www.beansoftware.com/ASP.NET-Tutorials/Write-Read-Delete-Session.aspx [< a href =http://www.beansoftware.com/ASP.NET-Tutorials/Write-Read-Delete-Session.aspxtarget =_ blanktitle =New Window> link ]了解更多关于会话的详细信息



You can refer this link http://www.beansoftware.com/ASP.NET-Tutorials/Write-Read-Delete-Session.aspx[link ] for more details about session


嗨朋友...

有多种技术可以做到这一点..

使用会话对象 - 一次验证完成后,您将获得会话中的用户名和密码,并将其放在另一页上。

示例 - :

使用会话变量..

在第一页上创建的会话

Hi Friend...
There are multiple technique you can do it..
using session object- Once authentication is done you will get username and password in session and get it on another page..
Example-:
Using Session Variable..
Session Created on first page
Session["UserName"] = txtName.Text;
Response.Redirect("WebForm2.aspx");





下面的代码显示了如何在另一个页面上获取会话值..

此代码必须放在第二页(WebForm2.aspx)



Below code shows how to get session value on another page..
this code must be placed on second page(WebForm2.aspx)

if(Session["UserName"] != null)
    Label3.Text = Session["UserName"].ToString();



如果你不喜欢t想要在标签中存储值(如果想在标签中存储值而不想显示set visible属性为false)请使用hiddenfield作为商店值...我认为,这是最好的方式..



就像上面的代码一样,你也可以在另一页上存储和获取密码..


If you don't want store values in label(if want to store values in label and don't want to display set visible property false) use hiddenfield for store values...I think, it's the best way..

Just like above code you can also store and get password on another page..


这篇关于存储和获取会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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