Perhaps a really strange question...
Is there a way that I can access the Server, Session Request and Response objects from the current page request from inside a class (not a web control) without explicitly passing them in from a web control?
My problem is that I have been developing my web application thinking that all static class members would be reset after each page request - but I've just realized that those members keep their values from request to request (and I assume across all users too?) This means I have some major restructuring to do, and the only way I can think of fixing this is to store my user-specific objects in the user session...and thus, I need access to the Session in some of my classes that accessed those static members. :S
Having a tough time wrapping my mind around the whole thing at the moment...I'm used to ASP 5.0. Maybe there's a better way to go about this altogether.
to access those items from a non-page class, you can use:
HttpContext.Current
this will give you access to
HttpContext.Current.Session
HttpContext.Current.Request
etc...
The class member properties/values wont be passed unless you are rebinding them, saving them in session/application or some other way passing them. It's more then likely a matter of how you are populating them that's causing you frustration.
Show the specific code you are using and what you think is the cause of the problem... we'll see what we can do to help out.
I think I know what you mean. Offloading stuff blindly into the user session is not a good idea. I have a lot of restructuring to do...
Speaking of which, there doesn't happen to be a convenient way to get the current instance of the System.Web.UI.Page object from within any class, is there? I couldn't find anything relevant to this in the HttpContext, and I don't know where else to look.
Thanks!!
you shoudnt need it in your class (the business layer should be UI independent).... if, for some reason you do though you'll have to pass in the instance of it.
Draggor:
there doesn't happen to be a convenient way to get the current instance of the System.Web.UI.Page object from within any class, is there?
You can get at the current page instance from HttpContext like this:
Dim currentPageAs Page =DirectCast(HttpContext.Current.Handler, Page)
0 comments:
Post a Comment