Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get global.asax build result or a new application instance?

11 views
Skip to first unread message

Marvin Landman

unread,
Nov 16, 2009, 7:57:06 AM11/16/09
to
Hi,

I have no active HttpContext but I need an application instance. I've
tried BuildManager.GetCompiledType without success.

On http://support.microsoft.com/kb/328534 I've found
HttpApplicationFactory.GetApplicationInstance internal method that works
for me but I would prefer a public method if there is one.

Thank you.

Regards,
Marvin

Paul Shapiro

unread,
Nov 16, 2009, 6:06:07 PM11/16/09
to
Is this what you're looking for?
System.Web.HttpContext context = System.Web.HttpContext.Current;

"Marvin Landman" <mar...@newsgroup.nospam> wrote in message
news:O9lDPxrZ...@TK2MSFTNGP06.phx.gbl...

Marvin Landman

unread,
Nov 17, 2009, 1:54:44 PM11/17/09
to
Paul Shapiro wrote:
> Is this what you're looking for?
> System.Web.HttpContext context = System.Web.HttpContext.Current;

No. I need an object derived from HttpApplication but I would like to
use the one defined in global.asax.

Patrice

unread,
Nov 18, 2009, 4:50:13 AM11/18/09
to
>> Is this what you're looking for?
>> System.Web.HttpContext context = System.Web.HttpContext.Current;
>
> No. I need an object derived from HttpApplication but I would like to use
> the one defined in global.asax.

So System.Web.HttpContext.Current.ApplicationInstance ?

Else you may want to give some details about the context ;-) so that we can
understand what you need. For now I assume you want to get at the
application instance for the current request at a place that doesn't expose
explicitely this information (that likely from a class library rather than
from a page).

--
Patrice


Marvin Landman

unread,
Nov 18, 2009, 4:59:57 AM11/18/09
to

Thank you for your response.

This would work but I would like to do the reverse. Create a HttpContext
and a HttpApplication rather than obtain an existing one.

Note that both of them is possible, I was able to use them but my
problem is that global.asax can define an application class derived from
HttpApplication that is used by ASP.NET in that case instead of a
generic HttpApplication.

So my question is that am I able to instantiate or obtain the type of
the class defined in global.asax without having a reference to an
application instance? (If I had an instance I could use GetType and
Activator.)

Marvin

Zhi-Qiang Ni[MSFT]

unread,
Nov 20, 2009, 2:55:38 AM11/20/09
to
Hi Marvin,

What my understanding of your requirement is that, you would like to get
the instance when the Application is started by the HttpApplicationFactory
instead of the instance of the current application. We know that when the
first request for the application arrives, the factory class extracts
information about the type of the application (the global.asax class),
creates the application state and fires the Application_OnStart event. The
factory selects a HttpApplication instance from the pool (like your said, a
internal method HttpApplicationFactory.GetApplicationInstance) and assigns
it to process the request. If no objects are available, a new
HttpApplication object is created. So, the requirement is seemed like how
to control the HttpApplicationFactory to select the different application
instances(maybe built by ourselves) for the request from the same
process(the pool).

Please correct me if I'm misunderstanding you.

--
Sincerely,

Zhi-Qiang Ni

Microsoft Online Support


==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================

--------------------
| Date: Wed, 18 Nov 2009 10:59:57 +0100
| From: Marvin Landman <mar...@newsgroup.nospam>
| User-Agent: Thunderbird 2.0.0.23 (Windows/20090812)
| MIME-Version: 1.0
| Subject: Re: How to get global.asax build result or a new application
instance?
| References: <O9lDPxrZ...@TK2MSFTNGP06.phx.gbl>
<#pjSiFxZ...@TK2MSFTNGP06.phx.gbl>
<uDSMvd7Z...@TK2MSFTNGP06.phx.gbl>
<#qZBISDa...@TK2MSFTNGP02.phx.gbl>
| In-Reply-To: <#qZBISDa...@TK2MSFTNGP02.phx.gbl>
| Content-Type: text/plain; charset=windows-1252; format=flowed
| Content-Transfer-Encoding: 7bit
| Message-ID: <e#1jkXDaK...@TK2MSFTNGP05.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: catv-80-98-131-226.catv.broadband.hu 80.98.131.226
| Lines: 1
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP05.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:94343
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Patrice

unread,
Nov 20, 2009, 4:23:23 AM11/20/09
to
Is this to run unit tests ?

> This would work but I would like to do the reverse. Create a HttpContext
> and a HttpApplication rather than obtain an existing one.

By defintion the httpContext is the context of the current web request. I'm
not sure how (or why) you could create this if you don't have a current
request. The same goes for the app. It is created as needed when a first
request hit the web site.

> Note that both of them is possible, I was able to use them but my problem
> is that global.asax can define an application class derived from
> HttpApplication that is used by ASP.NET in that case instead of a generic
> HttpApplication.

It doesn't look the same thing. You can have global.asax to use a type
derived from httpApplication and you are able to get at this instance IMO by
just getting at HttpContext.CurrentApplicationInstance. You have just to
cast to the appropriate type.

> So my question is that am I able to instantiate or obtain the type of the
> class defined in global.asax without having a reference to an application
> instance? (If I had an instance I could use GetType and Activator.)

It's still a bit unclear if the problem is in gettting the type you want
(AFAIK you'll just need to cast) or in really instanciating the object
without any real web request (for testing ?)

What is your preferred language (C# or VB ?) in case I would have a small
code sample to show that uses an HttpApplication derived class and that
obtain this same class in another context so that we can start from concrete
code to understand your rerquirements...

--
Patrice


Marvin Landman

unread,
Nov 20, 2009, 8:57:47 AM11/20/09
to
Thank you very much for your response.

HttpApplicationFactory.GetApplicationInstance works but it is an
internal method and I wonder if there is a more proper way of getting an
application instance or the type defined in global.asax.

But I am also interested in making HttpApplicationFactory to select a
different application than the one declared in global.asax (i.e. a
custom one) if that's possible.

Marving

Zhi-Qiang Ni[MSFT] rote:

Zhi-Qiang Ni[MSFT]

unread,
Nov 23, 2009, 1:35:52 AM11/23/09
to
Hi Marvin,

We need to confirm your requirement firstly.

After the request is processed into the web application, the current
HttpApplication instance would be created or selected by the
HttpApplicaitonFactory automatically, we cannot control this action. The
current HttpApplication is unique for the web application. Although we can
create a HttpContext and HttpApplication in the global.asax, it is
recommended that we define some properties in current HttpContext and
access them, but it is impossible to replace current instance with the
custom one. That means there is no public function that can get the custom
HttpApplication instance defined in the global.asax.

However, if you want to run Unit-Test or run the web application from other
programs (for example, a win form program). We can define custom
HttpContext firstly and then process request ourselves. Thus, the web
application will use the custom HttpContext as its current instance.

For example:
Request.Context =CustomContext;
HttpRuntime.ProcessRequest(Request);

--
Sincerely,

Zhi-Qiang Ni

Microsoft Online Support


==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================

--------------------
| Date: Fri, 20 Nov 2009 14:57:47 +0100


| From: Marvin Landman <mar...@newsgroup.nospam>
| User-Agent: Thunderbird 2.0.0.23 (Windows/20090812)
| MIME-Version: 1.0
| Subject: Re: How to get global.asax build result or a new application
instance?
| References: <O9lDPxrZ...@TK2MSFTNGP06.phx.gbl>
<#pjSiFxZ...@TK2MSFTNGP06.phx.gbl>
<uDSMvd7Z...@TK2MSFTNGP06.phx.gbl>
<#qZBISDa...@TK2MSFTNGP02.phx.gbl>

<e#1jkXDaK...@TK2MSFTNGP05.phx.gbl>
<Yh6wfbba...@TK2MSFTNGHUB02.phx.gbl>
| In-Reply-To: <Yh6wfbba...@TK2MSFTNGHUB02.phx.gbl>


| Content-Type: text/plain; charset=windows-1252; format=flowed
| Content-Transfer-Encoding: 7bit

| Message-ID: <eGWWylea...@TK2MSFTNGP05.phx.gbl>


| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: catv-80-98-131-226.catv.broadband.hu 80.98.131.226
| Lines: 1
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP05.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl

microsoft.public.dotnet.framework.aspnet:94431
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Marvin Landman

unread,
Nov 23, 2009, 4:16:40 AM11/23/09
to
Thank you all very much for your help.

> there is no public function that can get the custom
> HttpApplication instance defined in the global.asax

This was what I was looking for but now that you have confirmed that
this is not possible, I'll use HttpRuntime.ProcessRequest instead of
taking a shortcut to the custom HttpApplication instance.

My issue is now resolved.

Marvin

Justin S

unread,
Aug 26, 2011, 4:35:53 PM8/26/11
to
I am trying to host asp.net pages in a custom httpApplication and a new HttpContext. I really just want to be able to host pages inside of a new app domain. Have you accomplished something like that?

Thanks

> On Monday, November 16, 2009 7:57 AM Marvin Landman wrote:

> Hi,
>
> I have no active HttpContext but I need an application instance. I have
> tried BuildManager.GetCompiledType without success.
>
> On http://support.microsoft.com/kb/328534 I have found


> HttpApplicationFactory.GetApplicationInstance internal method that works
> for me but I would prefer a public method if there is one.
>
> Thank you.
>
> Regards,
> Marvin


>> On Monday, November 16, 2009 6:06 PM Paul Shapiro wrote:

>> Is this what you are looking for?
>> System.Web.HttpContext context = System.Web.HttpContext.Current;


>>> On Tuesday, November 17, 2009 1:54 PM Marvin Landman wrote:

>>> Paul Shapiro wrote:
>>>
>>> No. I need an object derived from HttpApplication but I would like to
>>> use the one defined in global.asax.


>>>> On Wednesday, November 18, 2009 4:50 AM Patrice wrote:

>>>> So System.Web.HttpContext.Current.ApplicationInstance ?
>>>>
>>>> Else you may want to give some details about the context ;-) so that we can
>>>> understand what you need. For now I assume you want to get at the

>>>> application instance for the current request at a place that does not expose


>>>> explicitely this information (that likely from a class library rather than
>>>> from a page).
>>>>

>>>> --
>>>> Patrice


>>>>> On Wednesday, November 18, 2009 4:59 AM Marvin Landman wrote:

>>>>> Patrice wrote:
>>>>>
>>>>> Thank you for your response.
>>>>>
>>>>> This would work but I would like to do the reverse. Create a HttpContext
>>>>> and a HttpApplication rather than obtain an existing one.
>>>>>
>>>>> Note that both of them is possible, I was able to use them but my
>>>>> problem is that global.asax can define an application class derived from
>>>>> HttpApplication that is used by ASP.NET in that case instead of a
>>>>> generic HttpApplication.
>>>>>
>>>>> So my question is that am I able to instantiate or obtain the type of
>>>>> the class defined in global.asax without having a reference to an
>>>>> application instance? (If I had an instance I could use GetType and
>>>>> Activator.)
>>>>>
>>>>> Marvin


>>>>>> On Friday, November 20, 2009 2:55 AM v-zhiqn wrote:

>>>>>> Hi Marvin,
>>>>>>
>>>>>> What my understanding of your requirement is that, you would like to get
>>>>>> the instance when the Application is started by the HttpApplicationFactory
>>>>>> instead of the instance of the current application. We know that when the
>>>>>> first request for the application arrives, the factory class extracts
>>>>>> information about the type of the application (the global.asax class),
>>>>>> creates the application state and fires the Application_OnStart event. The
>>>>>> factory selects a HttpApplication instance from the pool (like your said, a
>>>>>> internal method HttpApplicationFactory.GetApplicationInstance) and assigns
>>>>>> it to process the request. If no objects are available, a new
>>>>>> HttpApplication object is created. So, the requirement is seemed like how
>>>>>> to control the HttpApplicationFactory to select the different application
>>>>>> instances(maybe built by ourselves) for the request from the same
>>>>>> process(the pool).
>>>>>>

>>>>>> Please correct me if I am misunderstanding you.


>>>>>>
>>>>>> --
>>>>>> Sincerely,
>>>>>>
>>>>>> Zhi-Qiang Ni
>>>>>>
>>>>>> Microsoft Online Support
>>>>>>
>>>>>>
>>>>>> ==================================================
>>>>>> Get notification to my posts through email? Please refer to
>>>>>> http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
>>>>>>
>>>>>> MSDN Managed Newsgroup support offering is for non-urgent issues where an
>>>>>> initial response from the community or a Microsoft Support Engineer within
>>>>>> 2 business day is acceptable. Please note that each follow up response may
>>>>>> take approximately 2 business days as the support professional working with
>>>>>> you may need further investigation to reach the most efficient resolution.
>>>>>> The offering is not appropriate for situations that require urgent,
>>>>>> real-time or phone-based interactions. Issues of this nature are best
>>>>>> handled working with a dedicated Microsoft Support Engineer by contacting
>>>>>> Microsoft Customer Support Services (CSS) at
>>>>>> http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
>>>>>> ==================================================
>>>>>>
>>>>>> --------------------

>>>>>> | Date: Wed, 18 Nov 2009 10:59:57 +0100


>>>>>> | From: Marvin Landman <mar...@newsgroup.nospam>
>>>>>> | User-Agent: Thunderbird 2.0.0.23 (Windows/20090812)
>>>>>> | MIME-Version: 1.0
>>>>>> | Subject: Re: How to get global.asax build result or a new application
>>>>>> instance?

>>>>>> | Content-Type: text/plain; charset=windows-1252; format=flowed
>>>>>> | Content-Transfer-Encoding: 7bit

>>>>>> | Newsgroups: microsoft.public.dotnet.framework.aspnet
>>>>>> | NNTP-Posting-Host: catv-80-98-131-226.catv.broadband.hu 80.98.131.226
>>>>>> | Lines: 1

>>>>>> microsoft.public.dotnet.framework.aspnet:94343
>>>>>> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
>>>>>> |
>>>>>> | Patrice wrote:
>>>>>> | >>> Is this what you are looking for?


>>>>>> | >>> System.Web.HttpContext context = System.Web.HttpContext.Current;
>>>>>> | >> No. I need an object derived from HttpApplication but I would like to
>>>>>> use
>>>>>> | >> the one defined in global.asax.
>>>>>> | >
>>>>>> | > So System.Web.HttpContext.Current.ApplicationInstance ?
>>>>>> | >
>>>>>> | > Else you may want to give some details about the context ;-) so that we
>>>>>> can
>>>>>> | > understand what you need. For now I assume you want to get at the

>>>>>> | > application instance for the current request at a place that does not


>>>>>> expose
>>>>>> | > explicitely this information (that likely from a class library rather
>>>>>> than
>>>>>> | > from a page).
>>>>>> |
>>>>>> | Thank you for your response.
>>>>>> |
>>>>>> | This would work but I would like to do the reverse. Create a HttpContext
>>>>>> | and a HttpApplication rather than obtain an existing one.
>>>>>> |
>>>>>> | Note that both of them is possible, I was able to use them but my
>>>>>> | problem is that global.asax can define an application class derived from
>>>>>> | HttpApplication that is used by ASP.NET in that case instead of a
>>>>>> | generic HttpApplication.
>>>>>> |
>>>>>> | So my question is that am I able to instantiate or obtain the type of
>>>>>> | the class defined in global.asax without having a reference to an
>>>>>> | application instance? (If I had an instance I could use GetType and
>>>>>> | Activator.)
>>>>>> |
>>>>>> | Marvin
>>>>>> |


>>>>>>> On Friday, November 20, 2009 4:23 AM Patrice wrote:

>>>>>>> Is this to run unit tests ?
>>>>>>>
>>>>>>>

>>>>>>> By defintion the httpContext is the context of the current web request. I am
>>>>>>> not sure how (or why) you could create this if you do not have a current


>>>>>>> request. The same goes for the app. It is created as needed when a first
>>>>>>> request hit the web site.
>>>>>>>
>>>>>>>

>>>>>>> It does not look the same thing. You can have global.asax to use a type


>>>>>>> derived from httpApplication and you are able to get at this instance IMO by
>>>>>>> just getting at HttpContext.CurrentApplicationInstance. You have just to
>>>>>>> cast to the appropriate type.
>>>>>>>
>>>>>>>

>>>>>>> it is still a bit unclear if the problem is in gettting the type you want
>>>>>>> (AFAIK you will just need to cast) or in really instanciating the object


>>>>>>> without any real web request (for testing ?)
>>>>>>>
>>>>>>> What is your preferred language (C# or VB ?) in case I would have a small
>>>>>>> code sample to show that uses an HttpApplication derived class and that
>>>>>>> obtain this same class in another context so that we can start from concrete
>>>>>>> code to understand your rerquirements...
>>>>>>>
>>>>>>> --
>>>>>>> Patrice


>>>>>>>> On Friday, November 20, 2009 8:57 AM Marvin Landman wrote:

>>>>>>>> Thank you very much for your response.
>>>>>>>>
>>>>>>>> HttpApplicationFactory.GetApplicationInstance works but it is an
>>>>>>>> internal method and I wonder if there is a more proper way of getting an
>>>>>>>> application instance or the type defined in global.asax.
>>>>>>>>
>>>>>>>> But I am also interested in making HttpApplicationFactory to select a
>>>>>>>> different application than the one declared in global.asax (i.e. a

>>>>>>>> custom one) if that is possible.


>>>>>>>>
>>>>>>>> Marving
>>>>>>>>
>>>>>>>> Zhi-Qiang Ni[MSFT] rote:


>>>>>>>>> On Monday, November 23, 2009 1:35 AM v-zhiqn wrote:

>>>>>>>>> Hi Marvin,
>>>>>>>>>
>>>>>>>>> We need to confirm your requirement firstly.
>>>>>>>>>
>>>>>>>>> After the request is processed into the web application, the current
>>>>>>>>> HttpApplication instance would be created or selected by the
>>>>>>>>> HttpApplicaitonFactory automatically, we cannot control this action. The
>>>>>>>>> current HttpApplication is unique for the web application. Although we can
>>>>>>>>> create a HttpContext and HttpApplication in the global.asax, it is
>>>>>>>>> recommended that we define some properties in current HttpContext and
>>>>>>>>> access them, but it is impossible to replace current instance with the
>>>>>>>>> custom one. That means there is no public function that can get the custom
>>>>>>>>> HttpApplication instance defined in the global.asax.
>>>>>>>>>
>>>>>>>>> However, if you want to run Unit-Test or run the web application from other
>>>>>>>>> programs (for example, a win form program). We can define custom
>>>>>>>>> HttpContext firstly and then process request ourselves. Thus, the web
>>>>>>>>> application will use the custom HttpContext as its current instance.
>>>>>>>>>
>>>>>>>>> For example:
>>>>>>>>> Request.Context =CustomContext;
>>>>>>>>> HttpRuntime.ProcessRequest(Request);
>>>>>>>>>

>>>>>>>>> | Content-Type: text/plain; charset=windows-1252; format=flowed
>>>>>>>>> | Content-Transfer-Encoding: 7bit

>>>>>>>>> | Newsgroups: microsoft.public.dotnet.framework.aspnet
>>>>>>>>> | NNTP-Posting-Host: catv-80-98-131-226.catv.broadband.hu 80.98.131.226
>>>>>>>>> | Lines: 1

>>>>>>>>> microsoft.public.dotnet.framework.aspnet:94431
>>>>>>>>> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
>>>>>>>>> |
>>>>>>>>> | Thank you very much for your response.
>>>>>>>>> |
>>>>>>>>> | HttpApplicationFactory.GetApplicationInstance works but it is an
>>>>>>>>> | internal method and I wonder if there is a more proper way of getting an
>>>>>>>>> | application instance or the type defined in global.asax.
>>>>>>>>> |
>>>>>>>>> | But I am also interested in making HttpApplicationFactory to select a
>>>>>>>>> | different application than the one declared in global.asax (i.e. a

>>>>>>>>> | custom one) if that is possible.


>>>>>>>>> |
>>>>>>>>> | Marving
>>>>>>>>> |
>>>>>>>>> | Zhi-Qiang Ni[MSFT] rote:
>>>>>>>>> | > Hi Marvin,
>>>>>>>>> | >
>>>>>>>>> | > What my understanding of your requirement is that, you would like to
>>>>>>>>> get
>>>>>>>>> | > the instance when the Application is started by the
>>>>>>>>> HttpApplicationFactory
>>>>>>>>> | > instead of the instance of the current application. We know that when
>>>>>>>>> the
>>>>>>>>> | > first request for the application arrives, the factory class extracts
>>>>>>>>> | > information about the type of the application (the global.asax class),
>>>>>>>>> | > creates the application state and fires the Application_OnStart event.
>>>>>>>>> The
>>>>>>>>> | > factory selects a HttpApplication instance from the pool (like your
>>>>>>>>> said, a
>>>>>>>>> | > internal method HttpApplicationFactory.GetApplicationInstance) and


>>>>>>>>>> On Monday, November 23, 2009 4:16 AM Marvin Landman wrote:

>>>>>>>>>> Thank you all very much for your help.
>>>>>>>>>>
>>>>>>>>>>

>>>>>>>>>> This was what I was looking for but now that you have confirmed that

>>>>>>>>>> this is not possible, I will use HttpRuntime.ProcessRequest instead of

0 new messages