By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,089 Members | 1,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,089 IT Pros & Developers. It's quick & easy.

System.Reflection

P: n/a
JV
Is there a way to determine that an assembly is running under an ASP.NET web
application as opposed to a Windows application?

For example, in an ASP.NET application if I call
Assembly.GetExecutingAssembly(), can I determine that the current assembly
is a web application?
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
JV wrote:
Is there a way to determine that an assembly is running under an ASP.NET web
application as opposed to a Windows application?

For example, in an ASP.NET application if I call
Assembly.GetExecutingAssembly(), can I determine that the current assembly
is a web application?

You can check what class it's derived from, eg WinForm vs WebForm
Nov 16 '05 #2

P: n/a
JV,

I think a good way to test whether or not you are running in an ASP.NET
application is to access the static Current property on the HttpContext
class. If it is not running in ASP.NET, then the property should return
null.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"JV" <jo**********@goisc.com> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl...
Is there a way to determine that an assembly is running under an ASP.NET
web application as opposed to a Windows application?

For example, in an ASP.NET application if I call
Assembly.GetExecutingAssembly(), can I determine that the current assembly
is a web application?

Nov 16 '05 #3

P: n/a
Be aware if your solution doesn't have a reference to System.Web.dll, it
will throw an exception if you access System.Web.HttpContext.

bill

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Ol**************@TK2MSFTNGP12.phx.gbl...
JV,

I think a good way to test whether or not you are running in an ASP.NET application is to access the static Current property on the HttpContext
class. If it is not running in ASP.NET, then the property should return
null.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"JV" <jo**********@goisc.com> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl...
Is there a way to determine that an assembly is running under an ASP.NET
web application as opposed to a Windows application?

For example, in an ASP.NET application if I call
Assembly.GetExecutingAssembly(), can I determine that the current assembly is a web application?


Nov 16 '05 #4

P: n/a
bill:

I think you meant to say "yield a compiler error", not "throw an
exception exception"....

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 10 Mar 2005 14:08:08 -0600, "William F. Robertson, Jr."
<th****@nameht.org> wrote:
Be aware if your solution doesn't have a reference to System.Web.dll, it
will throw an exception if you access System.Web.HttpContext.

bill


Nov 16 '05 #5

P: n/a
Thanks for making me think about my response. <grin> I actually didn't
even mean exception, infact after reading my response, I think I just
randomly typed something in that sounded good...

Not all threads in a asp.net application have a HttpContext.Current attached
to it. You can use the HttpContext.Current if you want to know if the
calling thread ( current context) is currently processing a request through
the Http Pipeline, but it is not a reliable indicator that the calling
assembly is a windows application, or a web app. Timers, callbacks, user
created threads, etc will have a null value and can be from either.

Thanks for straightening me out Scott!

bill
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:cs********************************@4ax.com...
bill:

I think you meant to say "yield a compiler error", not "throw an
exception exception"....

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 10 Mar 2005 14:08:08 -0600, "William F. Robertson, Jr."
<th****@nameht.org> wrote:
Be aware if your solution doesn't have a reference to System.Web.dll, it
will throw an exception if you access System.Web.HttpContext.

bill

Nov 16 '05 #6

P: n/a
I have not tried this,

but instead of Assembly.GetExecutingAssembly(), try
Assembly.GetEntryAssembly()...

Greetings,
Henning Krause [MVP]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)
"JV" <jo**********@goisc.com> wrote in message
news:OP**************@TK2MSFTNGP09.phx.gbl...
Is there a way to determine that an assembly is running under an ASP.NET web application as opposed to a Windows application?

For example, in an ASP.NET application if I call
Assembly.GetExecutingAssembly(), can I determine that the current assembly
is a web application?

Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.