Properties instead of Session Variables

Properties instead of Session Variables

am 06.04.2008 02:19:17 von 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

Re: Properties instead of Session Variables

am 06.04.2008 16:06:28 von Stan

On 6 Apr, 01:19, pbd22 wrote:
> 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 =3D Request.QueryString("ip")
> folder =3D Request.QueryString("folder")
> slot =3D Request.QueryString("slot")
> file =3D DateTime.Now.ToFileTime().ToString() + ".wmv"
>
> Dim myfile =3D 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:
>
> =A0 =A0 =A0 =A0 Dim x As myVODfile
>
> =A0 =A0 =A0 =A0 Dim a As String =3D x.file
> =A0 =A0 =A0 =A0 Dim b As String =3D x.folder
> =A0 =A0 =A0 =A0 Dim c As String =3D x.ip
> =A0 =A0 =A0 =A0 Dim d As String =3D 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 =3D 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.

Re: Properties instead of Session Variables

am 06.04.2008 16:07:58 von patrice_scribe

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).

Re: Properties instead of Session Variables

am 06.04.2008 18:12:34 von Stan

On 6 Apr, 15:07, Patrice wrote:
> 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.

Re: Properties instead of Session Variables

am 08.04.2008 05:36:02 von Lucy

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

"Stan" wrote:

> On 6 Apr, 15:07, Patrice wrote:
> > 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.
>

Re: Properties instead of Session Variables

am 08.04.2008 14:16:00 von 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.

"Lucy" wrote in message
news:D7DA9F18-3742-4078-A5A5-2BA62AAE3935@microsoft.com...
> Application and Session vars. are BAAAAAD practice.
> Use cookies, viewstate (for user), file, or DB (Globally )
> -L
>
> "Stan" wrote:
>
>> On 6 Apr, 15:07, Patrice wrote:
>> > 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.
>>

Re: Properties instead of Session Variables

am 08.04.2008 18:26:07 von Patrice

Storing a file object in Application would a bit defeat the purpose plus I
was at first under the impression it was user related stuff...

IMO your best bet would be to explain what you are trying to do from a non
technical point of view. It could be easeir then to sugegst....



"Stan" a écrit dans le message de news:
e3a164ab-6b29-4246-98a6-3bf2600f6349@k1g2000prb.googlegroups .com...
> On 6 Apr, 15:07, Patrice wrote:
>> 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.