Saturday, March 24, 2012

Maintaining State on Master Page Without Session Variables

I have an asp.net 2.0 app that uses a sitemap, Master Page, and has
several content pages. While this feature has simplified the process of
creating a data-driven site menu, it does seem to have some big
restrictions.

Namely, maintaining state on the Master Page across all content pages.
I simply want to keep track of a key value across all content pages.
The only solution I can come up with is using a session variable, which
I hate.

Can't use ViewState because it preserves state across postbacks, and
when navigating through the menu we're not posting back but navigating
to a new page. Querystrings are not an option because the site
navigator uses the url defined in the site map to navigate to the next
page without providing an opportunity to inject querystrings.

Anyone come up with good way of handling this?

Thanks ...Maybe you could store it in a cookie, or an anonymous profile variable?

Sam wrote:

Quote:

Originally Posted by

I have an asp.net 2.0 app that uses a sitemap, Master Page, and has
several content pages. While this feature has simplified the process of
creating a data-driven site menu, it does seem to have some big
restrictions.
>
Namely, maintaining state on the Master Page across all content pages.
I simply want to keep track of a key value across all content pages.
The only solution I can come up with is using a session variable, which
I hate.
>
Can't use ViewState because it preserves state across postbacks, and
when navigating through the menu we're not posting back but navigating
to a new page. Querystrings are not an option because the site
navigator uses the url defined in the site map to navigate to the next
page without providing an opportunity to inject querystrings.
>
Anyone come up with good way of handling this?
>
Thanks ...


Quote:

Originally Posted by

Maybe you could store it in a cookie, or an anonymous profile variable?


I considered using a cookie, but they've always had such a bad
reputation ...

What's an "anonymous profile variable"?

Thanks for the reply ...
Sam,
Why do you hate Session variables?
If it is something site-wide, and not really user-specific like Session,
try storing it either in Applcation state, or in Cache.
Or, you could store whatever structure or other item in a static Hashtable
or other Collection object in Global.asax.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Sam" wrote:

Quote:

Originally Posted by

I have an asp.net 2.0 app that uses a sitemap, Master Page, and has
several content pages. While this feature has simplified the process of
creating a data-driven site menu, it does seem to have some big
restrictions.
>
Namely, maintaining state on the Master Page across all content pages.
I simply want to keep track of a key value across all content pages.
The only solution I can come up with is using a session variable, which
I hate.
>
Can't use ViewState because it preserves state across postbacks, and
when navigating through the menu we're not posting back but navigating
to a new page. Querystrings are not an option because the site
navigator uses the url defined in the site map to navigate to the next
page without providing an opportunity to inject querystrings.
>
Anyone come up with good way of handling this?
>
Thanks ...
>
>


Quote:

Originally Posted by

Sam,
Why do you hate Session variables?


I'm expecting this application to grow in volume and want to add
additional servers and a content switch. would like to leave the
sticky setting off on our cisco routers. We've not yet made use of the
features involving persisting session variables in SQL Server or
otherwise.

Thanks for the recommendations - they sound promising.

Sam

Quote:

Originally Posted by

If it is something site-wide, and not really user-specific like Session,
try storing it either in Applcation state, or in Cache.
Or, you could store whatever structure or other item in a static Hashtable
or other Collection object in Global.asax.
Peter
>
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
>
>
>
>
"Sam" wrote:
>

Quote:

Originally Posted by

I have an asp.net 2.0 app that uses a sitemap, Master Page, and has
several content pages. While this feature has simplified the process of
creating a data-driven site menu, it does seem to have some big
restrictions.

Namely, maintaining state on the Master Page across all content pages.
I simply want to keep track of a key value across all content pages.
The only solution I can come up with is using a session variable, which
I hate.

Can't use ViewState because it preserves state across postbacks, and
when navigating through the menu we're not posting back but navigating
to a new page. Querystrings are not an option because the site
navigator uses the url defined in the site map to navigate to the next
page without providing an opportunity to inject querystrings.

Anyone come up with good way of handling this?

Thanks ...

0 comments:

Post a Comment