473,806 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Htt pApplication,
Global.asax uses it).

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

Page Error Handler

public class PageBase : System.Web.UI.P age {
protected override void OnError(EventAr gs e) {
HttpContext ctx = HttpContext.Cur rent;
if (ctx == null) {
// is this even possible?
}
}

Application Error Handler

public class GlobalBase : System.Web.Http Application {
protected void Application_Err or(Object sender, EventArgs e) {
HttpContext ctx = HttpContext.Cur rent;
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 4315
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********@ava nsoft.com> wrote in message
news:uX******** ******@TK2MSFTN GP09.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.Htt pApplication,
Global.asax uses it).

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

Page Error Handler

public class PageBase : System.Web.UI.P age {
protected override void OnError(EventAr gs e) {
HttpContext ctx = HttpContext.Cur rent;
if (ctx == null) {
// is this even possible?
}
}

Application Error Handler

public class GlobalBase : System.Web.Http Application {
protected void Application_Err or(Object sender, EventArgs e) {
HttpContext ctx = HttpContext.Cur rent;
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.r illing.net> escribió en el mensaje
news:%2******** ********@TK2MSF TNGP15.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********@ava nsoft.com> wrote in message
news:uX******** ******@TK2MSFTN GP09.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.Htt pApplication, Global.asax uses it).

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

Page Error Handler

public class PageBase : System.Web.UI.P age {
protected override void OnError(EventAr gs e) {
HttpContext ctx = HttpContext.Cur rent;
if (ctx == null) {
// is this even possible?
}
}

Application Error Handler

public class GlobalBase : System.Web.Http Application {
protected void Application_Err or(Object sender, EventArgs e) {
HttpContext ctx = HttpContext.Cur rent;
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
1289
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 using ThreadStatic variables to maintain state for the current request but soon found out that this doesn't work in ASP.NET since one request can run on more than one thread. I then discovered an article...
2
3347
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 in the current session hasn't been set yet so I need to test it. I tried: If HttpContext.Current.Session("CustDataSet") = nothing then HttpContext.Current.Session("CustDataSet") = GetCustDataSet()
2
2155
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. : HttpContext.Current.Response.Cookies.Add("myNewCookie"); I am wondering if there are any landmines that I should know about, or if this will work pretty much as I am expecting a cookie should.
1
4320
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 HttpContext.Current.Server.MapPath to load an Xslt file to format and return Xml after the webrequest is made. Is there a way around this? Here some code... stateInfo = new StateInfo(manualEvents, strUrl);
0
5409
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 EndRequest (by turning response buffering off) then HttpContext.Current is set. To repo add the following to Global.asax protected void Application_PreSendRequestHeaders(object sender, EventArgs e) {...
2
12020
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 that I can't because HttpContext.Current.Session is null. (HttpContext.Current is fine though) I think there may be another server side method interfering with my ability to access the session.
14
29485
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 HttpContext.Current.Session is null, although for instance HttpContext.Current.Application or HttpContext.Current.Request is not null: public static class Admin {
0
2283
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 using VS 2008 but it gives me an error wen i run the same code in WPF broser APplication(xbap).. it throws an error saying Null reference encountered. the line of error is HTTPcontext context=HTTPcontext.Current; it goes in the else part of the...
3
8913
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 used Cache and Session objects, and currently I assume HttpContext.Current object to be existent. Also, since I do not have this check, some of my unit test cases fail because there is no HttpContext for them.
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9598
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10373
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5683
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.