|
-
May 4th, 2005, 10:16 PM
#6
I wonder how many charact
Re: Calling Page properties from a class
Well, a class has only the ability to work with what you provide to it.
Your errorhandler class will only be able to access Session if it has a context to operate in - hence the passing of the httpcontext that I demonstrated.
The typical webform in a asp.net application derives from System.Web.UI.Page. The Page class has as a property an HttpContext - which is the context associated with the current request (request for info from a browser client).
So in a webform (page class), .Net already provides you with the context. So you can easily access Session, Application, the user agent string, etc. Every request is a different context (.Net instantiates an instance of the page class when a request is made, does some processing, then destroys the instance - because the request has been served, and no doubt the next request will be somewhat different).
To bring this functionality into a regular class -you need to do the same thing the framework does, by making the current httpcontext available to the class. Whether you set a property, pass it in through the constructor, or pass it as a parameter to a method - somehow that information needs to get there.
To me - your situation could probably be easily solved by implementing Application_Error in the global asax. In there, you could easily pass the context:
Code:
private void Application_Error()
{
RasErrorHandler.HandleError(HttpContext.Current);
}
The RasErrorHandler class would implement a static method HandleError that accepts a HttpContext, fires off an email, then does a Response.Redirect to your generic error page.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|