2011-12-30 50 views
0

我有一个登录页面,将userName返回到名为User.aspx的页面。 User.aspx根据sql select显示关于用户的信息。我使用选择的结果填充页面上的12个标签。如果用户退出并再次进入页面,我想保留12个标签的信息。在会话中保存一个aspx页面

保存我的会话现在

 Session("UserPage") = (litHello.Text And litAddresse.Text And litAnimalGenre.Text And litCouriel.Text And litNomAnimal.Text And litPays.Text And litPostalCode.Text And litProvince.Text And litRace.Text And litTel.Text And litVille.Text) 

我怎么能进行得补我的所有的标签我保存的会话呼叫UserPage ???就是那个问题 !!!该代码是VB.NET 感谢的对我的帮助

回答

3

回答你的问题:

我会做多个属性的类并保存在session)

EG。

Public class PropertySession 
    Public Property ID as integer 
    Public Property Name as String 
    Public Property Address as String 
End Class 

然后(长路)

Dim currentPropertySession as PropertySession 
With PropertySession 
    .ID = litID.Text 
    .Name = litName.Text 
    .Address = litAddress.Text 
End With 

最后存储

Session("Property") = currentPropertySession 

或较短的方式(仍需要申报PropertySession)

Session("Property") = New PropertySession With { .ID = litID.Text, .Name = litName.Text, .Address = litAddress.Text} 

你可以即使这样做 - 只是为了合作mplete,但我不会做,如果我是你 -

Session("Property") = New Object With { .ID = litID.Text, .Name = litName.Text, .Address = litAddress.Text} 

附加 There are 8 ways to store data of a user to the next page.

退房哪一个是对你不够好。

+0

所以我必须做一个标签...没有另一种方式在pakage做到这一点? – FrankSharp 2011-12-30 16:09:16

+0

Bazinga - 下面检查 – NicoJuicy 2011-12-30 16:11:53

+0

那么以及如何检索DirectCast中的所有信息? – FrankSharp 2011-12-30 16:15:39

1

您可以继续按照自己的方式进行操作,然后在您读出会话时将值分割为数组,然后遍历数组。您将需要使用分隔符来分隔这些值,以便将它们分开。

Session("UserPage") = (litHello.Text & "|" & litAddresse.Text & "|" & litAnimalGenre.Text & "|" & litCouriel.Text & "|" & litNomAnimal.Text & "|" & litPays.Text & "|" & litPostalCode.Text & "|" & litProvince.Text & "|" & litRace.Text & "|" & litTel.Text & "|" & litVille.Text) 

的,当你读出的值:

dim userInfo as string() = Session("UserPage").toString().split("|") 

现在设置相应的标签

label1.text = userInfo(0) 
label2.text = userInfo(1) 
etc... 

这里的一个问题是,你必须确保在所有的值会话有价值,如果他们不填充空字符串"",以便您的分割将填充正确数量的值。

1

对于身份验证,您可以使用ASP.Net的开箱即用功能。它提供了一个带有标准提供程序的API,如SQL Membership Provider等。

通过使用web.config设置,您可以允许用户只访问您网站的某些部分(如成员区域)。然后,如果你想查询更多信息比成员资格提供API允许你,你可以从任何地方一样得到验证的用户身份(你自然键):

Page.User.Identity.Name 

有了这些信息,你可以查询数据库。