![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| ||||
| ||||
| I'm using forms authentication to log users into my site. I've just tried testing it with another user and it seems our sessions were being shared between us. All the pages have one master page and then content pages for each section. When he logged in, his home page appeared fine. If I then refreshed my home page, my master page showed the correct details for me, but my content page was showing the information relating to the other user. On my master page, I pass the userref to a public shared property within a seperate public class (App_Code/user_details) that stores the userref and is used to retrieve details about the user. Master Page code:- Code: sub Page_Load() . . . user_details.pcuser = HttpContext.Current.User.Identity.Name() Code: Public Class user_details
Private Shared _pcuser As Integer
Public Shared Property pcuser() As Integer
Get
Return _pcuser
End Get
Set(ByVal value As Integer)
_pcuser = value
End Set
End Property
Code: mycommand.parameters.addwithvalue("userref",user_details.pcuser)
I assumed a Shared property was shared in the application by session, not by all the sessions connected. I've used this methodology on a few sections of the site. I thought that was what seperate classes were used for. If I change it from Public Shared to something else, I can't then pass a value to it... ![]() Have I done something fundamentally wrong? ![]() How should I handle this? Should I allocate it to a variable on the Master page and then reference that on my content pages. The problem with that is I also want to reference it within other seperate classes, from which I can't access Master Page variables. Or is it to do with how the sessions are setup within my web.config? Code: <sessionState mode="InProc" cookieless="false" timeout="10" /> ![]() And on my birthday too.... Last edited by richyrich; May 15th, 2008 at 10:35 AM. |
| Sponsored Links |
|
#2
| ||||
| ||||
| You're declaring it as shared, thus the values will be overwritten and you will share that value.
__________________ jmurrayhead If you agree with me... click the icon! If my post solved your problem, click the button in the lower right-hand corner of the post.Join our Folding team: DeveloperBarn Folding |
|
#3
| ||||
| ||||
| I thought that mean't shared between pages, not users. So what should I change it to? How should I pass the value from my pages to the class without it being overwritten? |
|
#4
| ||||
| ||||
| You can use session variables: Code: Public Shared Property pcuser() As Integer
Get
Return HttpContext.Current.Session("pcuser")
End Get
Set(ByVal value As Integer)
HttpContext.Current.Session("pcuser") = value
End Set
End Property
|
|
#5
| ||||
| ||||
| You mean set it as a session on my Master Page and then retrieve it in the class? master page:- Code: HttpContext.Current.Session("pcuser") = HttpContext.Current.User.Identity.Name()
Code: Public Shared Property pcuser() As Integer
Get
Return HttpContext.Current.Session("pcuser")
End Get
Set(ByVal value As Integer)
HttpContext.Current.Session("pcuser") = value
End Set
End Property
|
|
#7
| ||||
| ||||
| I think I sorted it by just having:- Code: Public Shared ReadOnly Property pcuser() As Integer
Get
Return HttpContext.Current.User.Identity.Name()
End Get
End Property
![]() Thanks J I use the same methodology for gathering client details. One public class with a shared public property visitorref, which is set on the content pages where I need it. So, how could I handle this? If one user is viewing a client, the value could be changed by another user viewing a different client. I'm reluctant to use session variables as I've had problems with them being lost in the past with classic ASP. At the moment the ref is passed by a querystring and then set to the shared property in the client_details class. Then it's easy to just use client_details.forename, for instance, to get the info you need on the page. Any ideas? |
|
#8
| ||||
| ||||
| And I use it for a task system.... ![]() If I just change my pages so that I set the value of the relevant property in Page_Load, outside of If not IsPostBack then I presume the first thing it should do on Page_Load is set the value of the property to the correct value. The scenario I'm thinking of is a user clicks to view a task and passes a value to the property. As they're typing an update, a different user views a task, which would change the value of the property again. But, if when the first user clicks update, the Page_load should pass back the value of the task they were viewing. Is that right? |
|
#9
| ||||
| ||||
| By making it shared...it is just that...shared. You're sharing the same resource, thus making this not good. You don't necessarily have to use session variables. For example, you could have a class with public properties (not shared) that you populate every time the page loads. Code: Public Class UserInfo
Private _userName As String = String.Empty
Private _userEmail As String = String.Empty
Public Property UserName() As String
Get
Return _userName
End Get
Set(ByVal value As String)
_userName = value
End Set
End Property
Public Property UserEmail() As String
Get
Return _userEmail
End Get
Set(ByVal value As String)
_userEmail = value
End Set
End Property
End Class
Code: Dim currentUser As New UserInfo()
With currentUser
.UserName = HttpContext.Current.User.Identity.Name
.UserEmail = 'whatever you would get this information from
End With
You could also create constructors for the UserInfo class as to make it a bit easier. In the UserInfo class: Code: Public Sub New(ByVal userName As String, ByVal userEmail As String)
Me.UserName = userName
Me.UserEmail = userEmail
End Sub
Code: Dim currentUser As New UserInfo(HttpContext.Current.User.Identity.Name, "yourmom@mymom.com") |
|
#10
| ||||
| ||||
| It's more just the reference for each user, client, task etc. that I want to pass. What about if I did this? In my content pages have Code: Private task_details as New task_details() Would that solve the problem because they wouldn't be shared? Means I just have to add 1 line to each of my pages. |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Make File/Folder restricted to only certain users | Rebelle | Microsoft IIS | 16 | March 26th, 2008 02:06 PM |