views:

64

answers:

1

Is it possible to be notified in code when a session variable changes? Will give an example to make it clearer.

Its a normal ASP.NET site, with a master page and content pages. I want to show an image for the state of a user, ie logged in or not(2 different images). Instead of checking a session variable on every page_load of the master page, is it possible to set the image and only change it when that session variable is changed? Almost like firing a trigger when a change occurs.

+1  A: 

The Session Object (HTTPSessionState) doesn't have any OnChanged events as far as I know so you'll have to check each time, however the overhead of doing a check in the MasterPage Page_Load event is miniscule.

You should look at using the built in Membership Provider for doing this though as it has special Login/LoginStatus controls which will change state (you supply the template with your own images/styles etc...) when a user logs in/logs out/is anonymous

Eoin Campbell