I need to be able to change when I can see session state. I found out about the IRequiresSessionState Marker Interface, but have not been able to figure out how to use it. I think I may be missing something obvious. Can one of you C# guru’s give me a quick 1-2-3 step through (e.g)?
- Create a new class,
- Put
public interface IRequiresSessionStatein it. - Use
IRequiresSessionState('abra_cadabra')to change the value.
If I had a class:
public class PageToolsMarked, it would look like
public class PageTools : IRequiresSessionStateor with both interfaces,public class PageTools : IRequiresSessionState, IHttpHandler. In my case, my class needed only to be marked with the first. My handler needed both.implementfrom the menu (visual studio) and the necessary methods will be added to your class. Or you can look them up and add them manually.Once you have the IRequiresSessionState marker you can test to see if the session state is readonly and if so set a new http handler.
The http handler: MSDN will tell you a lot about HttpHandlers and HttpModules. In my case I needed a dummy handler so that I could access the session state when it was normally read only (
Page_PreInit). So in my class I added this:Here is a reference to a very elegant HttpModule class from which I got much or what I used. I hope this helps someone.