[Mono-list] HttpRuntime initialised check?

Marek Habersack grendello at gmail.com
Thu Aug 16 04:51:54 EDT 2007

On Tue, 14 Aug 2007 21:49:04 +0100, James Fitzsimons
<james.fitzsimons at gmail.com> scribbled:

> Hi all,
> I am doing a bit of work trying to get Spring.NET (specifically the web
> support) running on mono. I am using 1.2.5 preview 3 of the mono runtime
> at the moment.
> The problem is that in the spring code they attempt to check if the
> HttpRuntime has been fully initialised. They do this in a rather nasty
> fashion that will only ever work on the MS .NET runtime. The question I
> have for this list is:
> Is there a "correct" way to check if the HttpRuntime has finished it's
> initialisation?
> From this http://msdn2.microsoft.com/en-us/library/aa479328.aspx
> "The HttpRuntime object initializes a number of internal objects that
> will help carry the request out. Helper objects include the cache
> manager (the Cache object) and the internal file system monitor used to
> detect changes in the source files that form the application. The
> HttpRuntime creates the context for the request and fills it up with any
> HTTP information specific to the request. The context is represented by
> an instance of the HttpContext class."
> it looks like you could just check if the HttpContext wasn't null. Would
> that be a sufficient check?
No, alas. Context is created at the start of request processing (see
HttpRuntime.RealProcessRequest in mono source). But if you want to use a
similar hack they use for MS.NET runtime, check if you're running under Mono
(as Robert suggested) and then you can look up the 'firstRun' boolean
static field inside HttpRuntime. It is set to true until the first request
starts being processed. It is still a (very) ugly hack, but at least it will
let you work with the code.
I _think_ the check you could use in your code is making sure HttpRuntime.Cache
is not null. In Mono we set it towards the end of the HttpRuntime static
constructor - not sure how well it would work with MS.NET (if at all). Note
that this check would also be very fragile and error prone, since Cache might
be initialized somewhere else in the future.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-list/attachments/20070816/0a60361a/attachment.bin 

More information about the Mono-list mailing list