Properties instead of Session Variables

P

pbd22

Hi.

I can't use sessions because I am trying to set globally
accessible variables from the server - side of an ajax call.
I am thinking that a properties class that takes variables
in the same call would be a good way to access these
variables at other points in the program?

Accordingly, I have created the following:

Code:

ip = Request.QueryString("ip")
folder = Request.QueryString("folder")
slot = Request.QueryString("slot")
file = DateTime.Now.ToFileTime().ToString() + ".wmv"

Dim myfile = New myVODFile(ip, slot, folder, file)



Now, after setting the varibles for my myVODFile properties
class in the server code of my AJAX call, I want to use those
variables in the server code of """another""" ajax call. To do
this, I tried:

Code:

Dim x As myVODfile

Dim a As String = x.file
Dim b As String = x.folder
Dim c As String = x.ip
Dim d As String = x.slot



In the hopes of retreiving the same variables set earlier in the
program. But, I get "Nothing".

Could somebody explain to me if, what I am attempting is
correct and, if so, where I am going wrong?

I appreciate your time.

Thanks,
peter
 
S

Stan

Hi.

I can't use sessions because I am trying to set globally
accessible variables from the server - side of an ajax call.
I am thinking that a properties class that takes variables
in the same call would be a good way to access these
variables at other points in the program?

Accordingly, I have created the following:

Code:

ip = Request.QueryString("ip")
folder = Request.QueryString("folder")
slot = Request.QueryString("slot")
file = DateTime.Now.ToFileTime().ToString() + ".wmv"

Dim myfile = New myVODFile(ip, slot, folder, file)

Now, after setting the varibles for my myVODFile properties
class in the server code of my AJAX call, I want to use those
variables in the server code of """another""" ajax call. To do
this, I tried:

Code:

        Dim x As myVODfile

        Dim a As String = x.file
        Dim b As String = x.folder
        Dim c As String = x.ip
        Dim d As String = x.slot

In the hopes of retreiving the same variables set earlier in the
program. But, I get "Nothing".

Could somebody explain to me if, what I am attempting is
correct and, if so, where I am going wrong?

I appreciate your time.

Thanks,
peter

There are two key problems here.

One is that your code will not work even if there were no issues about
retention of data between postbacks (see below).

The line:

Dim x As myVODfile

merely creates a variable of type myVODfile but does not instantiate
it as an object. It will have no connection with the previous instance
named 'myfile'

If myfile still existed during the subsequent page request (Ajax call)
then it should be

Dim x As myVODfile = myfile

but then why bother with x at all?

The second problem is your apparent expectation that the assigned data
in myfile still exists. I don't yet know much about Ajax but I presume
that any variables that are declared are not retained between
postbacks unless stored as a Session state variable.

If you require the data in myfile to be shared globally (I presume you
mean among all site visitors at the same time) then the easiest way is
to store it a database which is normally shared by all users of the
application.

If you don't have database facilities then conceivably you could save
the data in a file using a fixed file name (best in the App_Data
folder where the ASP.NET worker process will have write privileges).
The problem then is how to co-ordinate read/write access to a single
file from multiple users. Not easy.

Hope that's of some use.
 
P

Patrice

Globally that is ? For a particular user (in which case i don't see
why you couldn't use session variables) or for all users (in which
case you could use application variables) ?

Keep in mind that http is stateless that is server side stuff is
created from zero with each new request. So you can't create something
server side and expect it to be available in the during the next round
trip without having this stored in a preserved location (pages are
usually using the viewstate that is an hidden field that is posted
with each new request to recreate the page in its previous state).
 
S

Stan

Globally that is ? For a particular user (in which case i don't see
why you couldn't use session variables) or for all users (in which
case you could use application variables) ?

Keep in mind that http is stateless that is server side stuff is
created from zero with each new request. So you can't create something
server side and expect it to be available in the during the next round
trip without having this stored in a preserved location (pages are
usually using the viewstate that is an hidden field that is posted
with each new request to recreate the page in its previous state).

I'd forgotten about the Application state, thanks Patrice for the
reminder (I've never used it).

To share the myfile object globally, assign it as:

Application("myfile") = myfile.

However there remains the problem of who owns it and is allowed to
overwrite it etc.
 
L

Lucy

Application and Session vars. are BAAAAAD practice.
Use cookies, viewstate (for user), file, or DB (Globally )
-L
 
G

George Ter-Saakov

Everything is BAAAAD... Even life itself considered to be a lethal
disease.... :)
So unless you work on second google.com you can use Session...

And totally do not see what is wrong with Application... just make sure you
know what you doing and do not put open DB connection in there....

PS: File is bad... hard to make it work in multi-user environment

George.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top