472,789 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 software developers and data experts.

Conditions for HttpContext == null

I have a 2 base classes that do error handling -- one for pages
(System.Web.UI.Page) and one for applications (System.Web.HttpApplication,
Global.asax uses it).

Are there any situations in either of these error handlers where
HttpContext.Current would be null?

Page Error Handler

public class PageBase : System.Web.UI.Page {
protected override void OnError(EventArgs e) {
HttpContext ctx = HttpContext.Current;
if (ctx == null) {
// is this even possible?
}
}

Application Error Handler

public class GlobalBase : System.Web.HttpApplication {
protected void Application_Error(Object sender, EventArgs e) {
HttpContext ctx = HttpContext.Current;
if (ctx == null) {
// how about this situation? is this possible?
}
}
}

If the context could be null in either situation, then I wouldn't be able to
get the exception information anyway. Should I just log it and return?
Nov 19 '05 #1
2 4242
I think one way would be when you are not running within a web site context,
just a normal application.

"Luis Esteban Valencia Muñoz" <le********@avansoft.com> wrote in message
news:uX**************@TK2MSFTNGP09.phx.gbl...
I have a 2 base classes that do error handling -- one for pages
(System.Web.UI.Page) and one for applications (System.Web.HttpApplication,
Global.asax uses it).

Are there any situations in either of these error handlers where
HttpContext.Current would be null?

Page Error Handler

public class PageBase : System.Web.UI.Page {
protected override void OnError(EventArgs e) {
HttpContext ctx = HttpContext.Current;
if (ctx == null) {
// is this even possible?
}
}

Application Error Handler

public class GlobalBase : System.Web.HttpApplication {
protected void Application_Error(Object sender, EventArgs e) {
HttpContext ctx = HttpContext.Current;
if (ctx == null) {
// how about this situation? is this possible?
}
}
}

If the context could be null in either situation, then I wouldn't be able to get the exception information anyway. Should I just log it and return?

Nov 19 '05 #2
Not in this case. ITs a web application.
"Peter Rilling" <pe***@nospam.rilling.net> escribió en el mensaje
news:%2****************@TK2MSFTNGP15.phx.gbl...
I think one way would be when you are not running within a web site context, just a normal application.

"Luis Esteban Valencia Muñoz" <le********@avansoft.com> wrote in message
news:uX**************@TK2MSFTNGP09.phx.gbl...
I have a 2 base classes that do error handling -- one for pages
(System.Web.UI.Page) and one for applications (System.Web.HttpApplication, Global.asax uses it).

Are there any situations in either of these error handlers where
HttpContext.Current would be null?

Page Error Handler

public class PageBase : System.Web.UI.Page {
protected override void OnError(EventArgs e) {
HttpContext ctx = HttpContext.Current;
if (ctx == null) {
// is this even possible?
}
}

Application Error Handler

public class GlobalBase : System.Web.HttpApplication {
protected void Application_Error(Object sender, EventArgs e) {
HttpContext ctx = HttpContext.Current;
if (ctx == null) {
// how about this situation? is this possible?
}
}
}

If the context could be null in either situation, then I wouldn't be
able to
get the exception information anyway. Should I just log it and return?


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John | last post by:
I'm trying to create a context object similar to the HttpContext that could be used by business objects independent of the origin or the call (ASP.NET or standalone). So I started out by...
2
by: moondaddy | last post by:
I need to set a variable to a session variable (if that's what you call it) like this: dim ds as dataset = HttpContext.Current.Session("CustDataSet") But I get an exception if this variable...
2
by: | last post by:
Today I learned that creating cookies inside of a custom class in ASP.NET 2.0 requires that you prefix it with HttpContext.Current..., e.g. : ...
1
by: Dave | last post by:
I'm trying call a couple WebRequests asynchronously using the QueueUserWorkItem, but one thing I noticed is that the HttpContext is null within the asynchronous call. I was using...
0
by: Aaron Morton | last post by:
I'm working on a IHttpModule that handles the PreSendRequestHeaders event from the HttpApplication, if the event is raised after EndRequest then HttpContext.Current is null. If it is raised before...
2
by: Dave | last post by:
After some digging, I discovered HttpContext.Current.Session is null when trying to access a session variable, username, in my upload.cs code which is in the App_Code folder. I just determined...
14
by: R.A.M. | last post by:
Hello, I have created ASP.NET project in which I have a file Admin.cs. It contains static class Admin with some methods and properties. The problem is that in property get a reference...
0
by: alister7 | last post by:
hi every1 im trying to download a music file from the database SQLserver.which i upload in the database.. The Code below works fine in wen i create a new project of an ASP.Net web application..m...
3
by: Madhur | last post by:
Hello I am delivering an asp.net 2.0 application to my customer. I need to know, If I need to check for the condition of HttpContext.Current to be null in my business logic. I have extensively...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.