Wednesday, March 28, 2012
the best way to have some information accessable to all pages?
I need to have access to some details in all my pages eg a Person object.
what is the best way to do it?
store in session object? or pass them through the QueryString or Application
variables etc?
what is the best and efficient way?It really depends on the nature of the application. Overall, I am not fond o
f
putting everything in hidden tags so it can travel on the Query String. It
potentially opens security holes.
Where you store information depends on the nature of the information.
If it is linked to the user, cookies are an option. For security, you can
send the user's token instead, or link it to the session ID. This will
require grabbing the information with each return, but it is safer than
storing in the cookie.
For session specific information, you can use the Session object as a cache.
You can also use the cache manager functionality of ASP.NET.
For page specific information (like the Person object is the person being
worked on, not the person using the app), you can use ViewState.
As I stated at the beginning, it really depends on the nature of the
application.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"Annie" wrote:
> hello all,
> I need to have access to some details in all my pages eg a Person object.
> what is the best way to do it?
> store in session object? or pass them through the QueryString or Applicati
on
> variables etc?
> what is the best and efficient way?
>
>
the best way to have some information accessable to all pages?
I need to have access to some details in all my pages eg a Person object.
what is the best way to do it?
store in session object? or pass them through the QueryString or Application
variables etc?
what is the best and efficient way?It really depends on the nature of the application. Overall, I am not fond of
putting everything in hidden tags so it can travel on the Query String. It
potentially opens security holes.
Where you store information depends on the nature of the information.
If it is linked to the user, cookies are an option. For security, you can
send the user's token instead, or link it to the session ID. This will
require grabbing the information with each return, but it is safer than
storing in the cookie.
For session specific information, you can use the Session object as a cache.
You can also use the cache manager functionality of ASP.NET.
For page specific information (like the Person object is the person being
worked on, not the person using the app), you can use ViewState.
As I stated at the beginning, it really depends on the nature of the
application.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"Annie" wrote:
> hello all,
> I need to have access to some details in all my pages eg a Person object.
> what is the best way to do it?
> store in session object? or pass them through the QueryString or Application
> variables etc?
> what is the best and efficient way?
>
Thursday, March 22, 2012
The existance of session variables
I was wondering how long the created session variables last for?
To be more clear, when are they destroyed? Do I have to set the variables to
null in Session_End()? Is the Session_End() method invoked when the browser
is closed?
I'm just not sure how it works.
Thanks in advance,
Tim.By default session variables expire 20 minutes since last page access. (You
can set this in web.config)
Session_End() is NOT invoked when the browser is closed.
Greg
"Timothy V" <tripix@.msn.com> wrote in message
news:%23vc45NEcEHA.796@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I was wondering how long the created session variables last for?
> To be more clear, when are they destroyed? Do I have to set the variables
to
> null in Session_End()? Is the Session_End() method invoked when the
browser
> is closed?
> I'm just not sure how it works.
> Thanks in advance,
> Tim.
>
Hi just started using session variables, no expert but this is what I have s
een so far.
Session variables exist from when the web application is started until it is
ended.
It is started when the browser of the user opens the start page and ends whe
n the user no longer has any page open from the application. Session variab
les are visible to all pages of the application when invoked.
--
Paul G
Software engineer.
"Timothy V" wrote:
> Hi,
> I was wondering how long the created session variables last for?
> To be more clear, when are they destroyed? Do I have to set the variables
to
> null in Session_End()? Is the Session_End() method invoked when the browse
r
> is closed?
> I'm just not sure how it works.
> Thanks in advance,
> Tim.
>
>
If only that were true!
You need to be very careful. Say you have a session variable
session("username")="greg". If the users walks away from the machine and
comes back 20+ minutes later and causes a postback on your page a new
session will start.
When you go to access your session("username") variable that you thought was
populated you'll get an exception because it will be now equal to nothing!
This scenario has caused me many many headaches. ;(
You can/should always check your session variables for nothing before using
them. Same will Cache items, cause those can be purged at any point in time.
PS: If anybody has ever figured at a full proof way of displaying a session
expired page while using forms authentication, I would love to hear it!
Greg
"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:182E0A10-B76F-4EFE-9B1F-A01ED839F4E3@.microsoft.com...
> Hi just started using session variables, no expert but this is what I have
seen so far.
> Session variables exist from when the web application is started until it
is ended.
> It is started when the browser of the user opens the start page and ends
when the user no longer has any page open from the application. Session
variables are visible to all pages of the application when invoked.
> --
> Paul G
> Software engineer.
>
> "Timothy V" wrote:
>
variables to
browser
for further reading
http://support.microsoft.com/defaul...kb;en-us;555082
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:182E0A10-B76F-4EFE-9B1F-A01ED839F4E3@.microsoft.com...
> Hi just started using session variables, no expert but this is what I have
> seen so far.
> Session variables exist from when the web application is started until it
> is ended.
> It is started when the browser of the user opens the start page and ends
> when the user no longer has any page open from the application. Session
> variables are visible to all pages of the application when invoked.
> --
> Paul G
> Software engineer.
>
> "Timothy V" wrote:
>
Sounds like a good idea to check if the session information is nothing as cu
rrently not doing that with my application so would cause problems--
Paul G
Software engineer.
"Greg Burns" wrote:
> If only that were true!
> You need to be very careful. Say you have a session variable
> session("username")="greg". If the users walks away from the machine and
> comes back 20+ minutes later and causes a postback on your page a new
> session will start.
> When you go to access your session("username") variable that you thought w
as
> populated you'll get an exception because it will be now equal to nothing!
> This scenario has caused me many many headaches. ;(
> You can/should always check your session variables for nothing before usin
g
> them. Same will Cache items, cause those can be purged at any point in tim
e.
> PS: If anybody has ever figured at a full proof way of displaying a sessio
n
> expired page while using forms authentication, I would love to hear it!
> Greg
>
> "Paul" <Paul@.discussions.microsoft.com> wrote in message
> news:182E0A10-B76F-4EFE-9B1F-A01ED839F4E3@.microsoft.com...
> seen so far.
> is ended.
> when the user no longer has any page open from the application. Session
> variables are visible to all pages of the application when invoked.
> variables to
> browser
>
>
The existance of session variables
I was wondering how long the created session variables last for?
To be more clear, when are they destroyed? Do I have to set the variables to
null in Session_End()? Is the Session_End() method invoked when the browser
is closed?
I'm just not sure how it works.
Thanks in advance,
Tim.By default session variables expire 20 minutes since last page access. (You
can set this in web.config)
Session_End() is NOT invoked when the browser is closed.
Greg
"Timothy V" <tripix@.msn.com> wrote in message
news:%23vc45NEcEHA.796@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I was wondering how long the created session variables last for?
> To be more clear, when are they destroyed? Do I have to set the variables
to
> null in Session_End()? Is the Session_End() method invoked when the
browser
> is closed?
> I'm just not sure how it works.
> Thanks in advance,
> Tim.
Hi just started using session variables, no expert but this is what I have seen so far.
Session variables exist from when the web application is started until it is ended.
It is started when the browser of the user opens the start page and ends when the user no longer has any page open from the application. Session variables are visible to all pages of the application when invoked.
--
Paul G
Software engineer.
"Timothy V" wrote:
> Hi,
> I was wondering how long the created session variables last for?
> To be more clear, when are they destroyed? Do I have to set the variables to
> null in Session_End()? Is the Session_End() method invoked when the browser
> is closed?
> I'm just not sure how it works.
> Thanks in advance,
> Tim.
>
If only that were true!
You need to be very careful. Say you have a session variable
session("username")="greg". If the users walks away from the machine and
comes back 20+ minutes later and causes a postback on your page a new
session will start.
When you go to access your session("username") variable that you thought was
populated you'll get an exception because it will be now equal to nothing!
This scenario has caused me many many headaches. ;(
You can/should always check your session variables for nothing before using
them. Same will Cache items, cause those can be purged at any point in time.
PS: If anybody has ever figured at a full proof way of displaying a session
expired page while using forms authentication, I would love to hear it!
Greg
"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:182E0A10-B76F-4EFE-9B1F-A01ED839F4E3@.microsoft.com...
> Hi just started using session variables, no expert but this is what I have
seen so far.
> Session variables exist from when the web application is started until it
is ended.
> It is started when the browser of the user opens the start page and ends
when the user no longer has any page open from the application. Session
variables are visible to all pages of the application when invoked.
> --
> Paul G
> Software engineer.
>
> "Timothy V" wrote:
> > Hi,
> > I was wondering how long the created session variables last for?
> > To be more clear, when are they destroyed? Do I have to set the
variables to
> > null in Session_End()? Is the Session_End() method invoked when the
browser
> > is closed?
> > I'm just not sure how it works.
> > Thanks in advance,
> > Tim.
for further reading
http://support.microsoft.com/defaul...kb;en-us;555082
--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:182E0A10-B76F-4EFE-9B1F-A01ED839F4E3@.microsoft.com...
> Hi just started using session variables, no expert but this is what I have
> seen so far.
> Session variables exist from when the web application is started until it
> is ended.
> It is started when the browser of the user opens the start page and ends
> when the user no longer has any page open from the application. Session
> variables are visible to all pages of the application when invoked.
> --
> Paul G
> Software engineer.
>
> "Timothy V" wrote:
>> Hi,
>> I was wondering how long the created session variables last for?
>>
>> To be more clear, when are they destroyed? Do I have to set the variables
>> to
>> null in Session_End()? Is the Session_End() method invoked when the
>> browser
>> is closed?
>>
>> I'm just not sure how it works.
>>
>> Thanks in advance,
>>
>> Tim.
>>
>>
>
Tuesday, March 13, 2012
The lifecycle of Cache
I want to use System.Web.Caching.Cache in my web application, but I want to
know the lifecycle of Cache (depending on Page, Session or Application ...).
Thanks!
Enoshre:
Quote:
Originally Posted by
I want to know the lifecycle of Cache (depending on Page, Session or Application ...).
One instance of the Cache class is created per application domain,
and it remains valid as long as the application domain remains active.
You can insert items in the Cache :
1. with a key dependency ( When a key dependency changes, the object becomes invalid
and is removed from the cache ). You can opt to have it replaced with a new key dependency.
2. with a file dependency ( When any dependency changes, the object becomes invalid
and is removed from the cache ). You can opt to have it replaced with a new dependency.
3. With a SQLDependency, based on a SQL Server table or query.
When the data changes, so does the cache.
4. with an absoluteExpiration time
5. with a slidingExpiration time
You can also set up a notification when the item is removed from the cache.
See :
http://msdn2.microsoft.com/en-us/library/4y13wyk9.aspx
http://msdn2.microsoft.com/en-us/li...eb.caching.aspx
http://msdn2.microsoft.com/en-us/li...hing.cache.aspx
http://msdn2.microsoft.com/en-us/li...dependency.aspx
For specific usage, see Cache Insert :
http://msdn2.microsoft.com/en-us/li...che.insert.aspx
There's other types of caching, like Output Caching.
You can control its duration with the "Duration parameter :
<%@. OutputCache Duration="#ofseconds"
See :
http://msdn2.microsoft.com/en-us/library/hdxfb6cy.aspx
You can also use partial caching ( caching user controls, for example ):
See:
http://msdn2.microsoft.com/en-us/li...duration.asp x
http://msdn2.microsoft.com/en-us/li...gattribute.aspx
As you can see, there's a number of answers to your question,
depending on the type of caching you perform.
Read the supplied links and decide which type of caching,
and for which duration, is the caching you want to implement.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"Enosh Chang" <changenosh@.yahoo.com.twwrote in message
news:u5ek0p37GHA.4404@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
Hi all:
>
I want to use System.Web.Caching.Cache in my web application, but I want to know the lifecycle of
Cache (depending on Page, Session or Application ...). Thanks!
>
Enosh
>
Juan's answer is good. Just thought I'd mention that the word you are
looking for is "scope", not "lifecycle".
Karl
--
http://www.openmymind.net/
http://www.codebetter.com/
"Enosh Chang" <changenosh@.yahoo.com.twwrote in message
news:u5ek0p37GHA.4404@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
Hi all:
>
I want to use System.Web.Caching.Cache in my web application, but I want
to know the lifecycle of Cache (depending on Page, Session or Application
...). Thanks!
>
Enosh
>
The lifecycle of Cache
I want to use System.Web.Caching.Cache in my web application, but I want to
know the lifecycle of Cache (depending on Page, Session or Application ...).
Thanks!
Enoshre:
> I want to know the lifecycle of Cache (depending on Page, Session or Application .
.).
One instance of the Cache class is created per application domain,
and it remains valid as long as the application domain remains active.
You can insert items in the Cache :
1. with a key dependency ( When a key dependency changes, the object become
s invalid
and is removed from the cache ). You can opt to have it replaced with a new
key dependency.
2. with a file dependency ( When any dependency changes, the object becomes
invalid
and is removed from the cache ). You can opt to have it replaced with a new
dependency.
3. With a SQLDependency, based on a SQL Server table or query.
When the data changes, so does the cache.
4. with an absoluteExpiration time
5. with a slidingExpiration time
You can also set up a notification when the item is removed from the cache.
See :
http://msdn2.microsoft.com/en-us/library/4y13wyk9.aspx
http://msdn2.microsoft.com/en-us/li...eb.caching.aspx
http://msdn2.microsoft.com/en-us/li...hing.cache.aspx
http://msdn2.microsoft.com/en-us/li...cy.asp
x
For specific usage, see Cache Insert :
[url]http://msdn2.microsoft.com/en-us/library/system.web.caching.cache.insert.aspx[/url
]
There's other types of caching, like Output Caching.
You can control its duration with the "Duration parameter :
<%@. OutputCache Duration="#ofseconds"
See :
http://msdn2.microsoft.com/en-us/library/hdxfb6cy.aspx
You can also use partial caching ( caching user controls, for example ):
See:
http://msdn2.microsoft.com/en-us/li... />
ation.aspx
http://msdn2.microsoft.com/en-us/li...te.asp
x
As you can see, there's a number of answers to your question,
depending on the type of caching you perform.
Read the supplied links and decide which type of caching,
and for which duration, is the caching you want to implement.
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"Enosh Chang" <changenosh@.yahoo.com.tw> wrote in message
news:u5ek0p37GHA.4404@.TK2MSFTNGP04.phx.gbl...
> Hi all:
> I want to use System.Web.Caching.Cache in my web application, but I want t
o know the lifecycle of
> Cache (depending on Page, Session or Application ...). Thanks!
> Enosh
>
Juan's answer is good. Just thought I'd mention that the word you are
looking for is "scope", not "lifecycle".
Karl
http://www.openmymind.net/
http://www.codebetter.com/
"Enosh Chang" <changenosh@.yahoo.com.tw> wrote in message
news:u5ek0p37GHA.4404@.TK2MSFTNGP04.phx.gbl...
> Hi all:
> I want to use System.Web.Caching.Cache in my web application, but I want
> to know the lifecycle of Cache (depending on Page, Session or Application
> ...). Thanks!
> Enosh
>