Skip navigation.

Another (New) Book Is Here!All recent postsHappy Holidays!

I Swear I Didn't Know I Could Do This!

I’m a big fan of HttpModules and HttpHandlers. Hey, I even created a tool to code-gen those for you!

Here’s one gotcha with HttpModules: if you invoke code which relies on HttpContext.Current, it may be null, as in the case of kicking off a timer which lives on its own, separate thread.

I dug into HttpContext with Reflector and noticed that the HttpContext.Current property had a setter. Imagine my surprise when I did the following, and it worked!

private void ScheduleCallback (object state)
{
    // ...
    HttpContext.Current = state as HttpContext;
    // ...
}

I don’t know if I’m violating anything here, but it functions just fine. I’ll take that.

Btw, this post clarifies what that state is.

Comments

No comments yet

Emails and Notifications

Would you like to be notified when somebody responds to this post? 

Submit your comment

Please enter only text since all HTML tags except hyperlinks will be stripped. Hyperlinks will become live links. Any comments with flaming or offensive language will be deleted. Be courteous to other posters. Thank you.

Your name (required):
Your email (optional):
Your site's URL (optional):
Enter this number
Type in the number above:
Comment (required):