IIS7 Integrated Mode - "Request is not available in this context" - FirstRequestInitialization

119 views
Skip to first unread message

David Christiansen

unread,
Nov 6, 2009, 3:05:20 PM11/6/09
to sutekishop
Hi all,
Just started looking into Suteki Shop and really like what I see so
far - well done to all involved.

Hosting the source on my local environment I ran into the old
favourite "Request is not available in this context" when the site is
hosted under IIS 7 (or 7.5) with an application pool in integrated
mode. I have found this in the past and it is down to accessing the
context when there hasn't yet been one established.

I notice that Jeremy has already written a FirstRequestInitialization
class which is exactly what I was going to propose to fix the issue.
Is there a plan for integrating this into global.asax.cs at any point?

My assumption is something along the lines of

protected void Application_BeginRequest(Object source,
EventArgs e)
{
HttpApplication app = (HttpApplication)source;
HttpContext context = app.Context;
FirstRequestInitialization.Initialize(context, Init);
}

void Init()
{
RouteManager.RegisterRoutes(RouteTable.Routes);
InitializeWindsor();
DbConnectionCheck();
}

All right guys, talk to you soon - great work! The way things are
looking my ecommerce project will be built upon this project!

--
David Christiansen

Mike Hadlow

unread,
Nov 7, 2009, 10:28:44 AM11/7/09
to sutekishop
Hi David,

I'm very pleased that you like the shop :) Keep us updated on your
project, I'd love to see it when it's ready.

Yes, this issue has been around for a while now:
http://code.google.com/p/sutekishop/issues/detail?id=10

I'm still hosting on 2003, so I haven't had any incentive to fix it
(yeah, I know, I should pull my finger out :) Like you mention, I
think Jeremy looked at it briefly too. The comments on the issue from
Graham O'Neale look promissing, so you'd probably want to check out
his blog post too.

If you get it fixed, please send me a patch.

Many thanks
Mike

On Nov 6, 8:05 pm, David Christiansen <da...@davidchristiansen.com>
wrote:

David Christiansen

unread,
Nov 7, 2009, 8:18:05 PM11/7/09
to sutekishop
Hi Mike,
I can confirm that moving initialisation to Application_BeginRequest
resolves the issue for Integrated mode on IIS7. I cannot test it on
2003 / IIS6 however tests on IIS7 classic mode appear to prove that
the fix is backward compatible.

I have uploaded a patch file to the issue you mentioned (in fairness,
I ain't done much) - let's test it on your environment and try find if
there are any probs :)

Cheers,
DC
Reply all
Reply to author
Forward
0 new messages