Last post Nov 29, 2016 01:54 PM by funky_fox
Nov 24, 2016 06:48 PM|funky_fox|LINK
I am sure this must be possible but have so far drawn a blank.
I'm storing a list of logged on users in the sites application state object. There is also some user specific information stored in the cache, this info has a cacheItemRemovedCallback which closes the session on the database.
I'm trying to get the cacheItemRemovedCallback to also update the users table stored in the application state and have tried various ways which gives various errors:
1 - httpContext.current.application("usersTable").. do stuff..
..this compiles ok but gives an error ( NullReferenceException ) when cacheItemRemovedCallback fires.. I realised this is because since it's triggered by cacheItemRemovedCallback then there isn't an httpContext to reference and so can't access the application..
fair enough and to be expected!
2 - application("usersTable").. do stuff.. This fails to compile since 'Reference to a non-shared member requires an object reference'.. again, to be expected.
So my question is, is there a way I can access the application object without an httprequest to reference.
I've trawled google and various forums but no luck so any input would be great!
Nov 25, 2016 12:28 AM|funky_fox|LINK
After another few hours googling and hacking I've come up with a workaround. It's a bit of a dirty hack but it works.
The solution is to define a module with a single variable declaration..
public module mySiteContext
public application as httpApplicationState
Then set this property during application_start in global.asax
You can then reference the application from anywhere replacing httpContext.Current.application with
As I said it's a hack but it seems to work.
If anyone has a better solution then please let me know.
With thanks to Culme in this post
Nov 28, 2016 07:38 AMfirstname.lastname@example.org|LINK
As far as I know, Application state is not shared between multiple servers within a Web farm or between worker processes in a Web garden.
Therefore, application state is a useful place to store small amounts of often-used data that does not change from one user to another.
In my opinion, we could directly access the application state in the application, why you use
Nov 29, 2016 01:54 PM|funky_fox|LINK
Thanks for the reply.
..why you use httpContext?
My problem was trying to get a reference to the application without a request to give it context.. ie, if you are trying to access application from a callback function.
the only way I've found so far is as mentioned above.