 |
|
|
 |
|
|
 |
|
 |
It's sound too good to be true, but when the same user opens up another browser, the new browser continues using the same session object.
The problem arises when the new browser performs some changes on the session object (i.e. changing id's, etc), the user switches to the old browser and the information it was expecting is not longer there (or worse still, for example, was expecting to save changes to record id = 10, when the id was changed to 11 with the new browser).
The following article suggests a solution, but this only works when the same page is posting back to itself:
http://www.codeproject.com/aspnet/BusinessObjsSessionState.asp
Does anyone have ideas how to either:
- only save one business object for one user, regardless of the number of browsers open? or
- saving mutiple business objects for mutiple browswer windows for the one user?
Kind regards,
Mathew
|
|
|
|
 |
|
 |
Lovely artcle, thank you so much for posting it. Please bear with me as I'm pseudo-new to C# and OOP.
Can anyone expound on the use of the text "GetSet" before most of the properties defined in the class? Is that a stylistic choice or is it for some reason mandatory? I'm about to test it myself and will most likely discover the answer, but some experienced feedback would be quite welcome.
Thanks so much!
Regards,
meLecrone
|
|
|
|
 |
|
 |
The Get and Set inside the body of the Property is mandatory. In C# it looks like this:
private string someProp;
public string SomeProperty
{
get{return someProp;}
set{someProp = value;}
}
This encapsulates access to someProp. In Java property getter setters are known as Accessor Mutators.
Simon Segal
|
|
|
|
 |
|
 |
While looking up techical questions, I find an old friend. I not interested in this aritical but, really thought highly of the author. You are all really lucky to have this guy on the board. I'm leading 135 people in an implementation in Pasadena of an electronic medical chart system. We ate at the Cheesecake Factory about eight years ago on the corner of Fair Oaks and Colorado. Starting companies was fun and a took its toll.
As I look back, it was never about the money, just character. Hope you are well. As someone close to you may always need character help, Simon never will.
Success mate,
ABE in LA
|
|
|
|
 |
|
 |
Good idea, very OO
One suggestion: make it serializable by inherited from ISerializable, so it can support SQL server session store or state server.
And, I would like call this class a state class. If session is not allowed, you can even persist it using viewstate. I will use this method in my next project, thank you.
|
|
|
|
 |
|
 |
Nice suggestions Yao. One reader has already touched on this (see the posted message 'Problems using this when storing session state in SQL Server' below). His particular problem was taken care of using the Serialiazable attribute.
Simon Segal
|
|
|
|
 |
|
 |
Hi I am new To ASP.Net and came across your article. As I am not familar with C#, I converted it to vb.net. Everything worked fine in the conversion. I initiated the class in the Session On Start in global.asax, and in my Login.aspx pages I set the values. I was able to get the values in the login.aspx page but when I opened another page like default.aspx I couldn't get the values I had set in the login.aspx page. What Am I doing wrong This is what I did in the login page CType(Session("SessionSink"), RSVP.SessionSink).GetSetLoginStatus ="VALID" And in the Default.aspx page in the page load I had Msg.Text=CType(Session("SessionSink"), RSVP.SessionSink).GetSetLoginStatus This showed empty Any help will be appreciated Thank you
Geogie Varughese
|
|
|
|
 |
|
 |
I am not sure Geogie. From what you describe I cant see why it's not working for you. Is it possible that you have left something out in describing your scenario? I assume for example that you can only get to default.aspx by first clearing authentication in the login.aspx page .
Simon Segal
|
|
|
|
 |
|
 |
Hi
Thank you Mr Segal for your prompt reply. I got it to work.
I am not sure what the problem was.
What I did was to remove the page and create it from scratch and put the same code back.
Anyway it was an excellent tip from you.
Thank you very much
Geogie
|
|
|
|
 |
|
 |
I have a problem with session objects and I thought of asking you coz you seem to have worked with sessions a bit more than anyone else I am aware of...
I have in Session_Start:
protected void Session_Start(Object sender, EventArgs e)
{
cms.errorHandler error = new cms.errorHandler();
Session["error"] = error;
}
Note that the cms. is because the errorHandler class in in a subfolder called cms.
Now, in my code in a web service I have:
errorHandler error = (errorHandler)Session["error"];
This throws an Exception:
Object Reference not set to an instance of an object (NullReferenceException)
Obviously the Session object is null, thats why it throws the exception, at least this is what I understand.
Is there another way to access that object? Do I have to define it in a different way?
|---------------|
| theJazzyBrain |
|---------------|
|
|
|
|
 |
|
 |
Have you set the WebMethod attribute for EnableSession = true ?
Eg
[WebMethod(Description="SomeDescription",EnableSession=true)]
public string testSession()
{
errorHandler error = (errorHandler)Session["error"];
.......etc etc
}
Simon Segal
|
|
|
|
 |
|
 |
Thank you very much...
I had no idea that you can set attribute there
|---------------|
| theJazzyBrain |
|---------------|
|
|
|
|
 |
|
 |
Always happy to help. By the way are you using the SessionSink as per the article? Just curious.
Simon Segal
|
|
|
|
 |
|
 |
No, I am not...
although it looks nice and tidy...
This is a project for my final project at university so I dont want to use other peoples code. If I use it I will have to reference your name
I am trying to write as much code as I can on my own and use my own ideas...
If it was a comercial project I would use it for sure..
|---------------|
| theJazzyBrain |
|---------------|
|
|
|
|
 |
|
 |
How I can implement the same thing in VB.Net? I have tried but not able to do so? Can anybody help?
|
|
|
|
 |
|
 |
What exactly is holding you back at this stage? Is just a syntax problem or something else?
Simon Segal
|
|
|
|
 |
|
 |
I feel its syntax problem only. I was able to create the sessionlink class, but failed to create a new instance of that class WITH the Session variable in the session on start event.
Also thanks for a quick reply.
|
|
|
|
 |
|
 |
Where you creating the instance like this?
VB.Net
Session("SessionSink") = New SessionSink();
as opposed to
C#
Session["SessionSink"] = new SessionSink();
Simon Segal
|
|
|
|
 |
|
 |
this I am doing correctly, but how to use this in a form. OK, below is the sample I am trying to create.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Class File:
Imports System
Imports System.Data.SqlClient
Public Class sessionSink
Private strGetCode As String
Public Sub refresh()
strGetCode = ""
End Sub
Public Property codeValue()
Get
Return strGetCode
End Get
Set(ByVal Value)
strGetCode = Value
End Set
End Property
End Class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Implementation in a Form....
Private Sub cmdButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdButton.Click
sessionSink(Session("sessionsink")).codeValue = 1
End Sub
|
|
|
|
 |
|
 |
I see. You arent casting the Session variable that
holds the Sink correctly.
C# Cast
((SessionSink)(Session["SessionSink"])).codeValue = 1;
VB.Net Cast
ctype(Session("SessionSink"), SessionSink).codeValue = 1
Simon Segal
|
|
|
|
 |
|
 |
It worked....Thanks a ton!!!u are genious.....
|
|
|
|
 |
|
|
 |
|
 |
Session("SessionSink") = New SessionSink()
'i'm getting and error message that SessionSink is not defined
it most likely to be a syntax error pls help
|
|
|
|
 |