Home All Groups Group Topic Archive Search About

How to determine if I am in a web or a windows application

Author
21 Sep 2006 7:59 AM
Jean Paul Mertens
Hello to all,

I use a lib class to handle all my exeption errors ocured in my objects.
Since my objects are used in windows applications as well as in web
applications, I would like to determine in my lib class if she is serving a
web or a windows application. Is there a neat way to detect this.

Greets

Jean.Paul

Author
21 Sep 2006 8:35 AM
Herfried K. Wagner [MVP]
"Jean Paul Mertens" <ON7AMI@newsgroups.nospam> schrieb:
> I use a lib class to handle all my exeption errors ocured in my objects.
> Since my objects are used in windows applications as well as in web
> applications, I would like to determine in my lib class if she is serving
> a web or a windows application. Is there a neat way to detect this.

Check out 'System.Reflection.Assembly.GetEntryAssembly'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
21 Sep 2006 8:39 AM
Sundar Narasimman
Hello Jean Paul,

You could do it by figuring out the which program/assembly is calling the
exception handling library. Based on that you can differentiate whether
win/web app is calling .

If you don't have control over exception handling library, meaning if the
lib is blackbox to you, the only way to attack this scenario is to play with
generated exception message. Try adding more information to the exception
message of the exception object and call the exception handling library with
the exception.

Pls let me know whether this is useful to you and let me know whether you
need more information


--
Thanks & Regards,
Sundar Narasimman


Show quote
"Jean Paul Mertens" wrote:

> Hello to all,
>
> I use a lib class to handle all my exeption errors ocured in my objects.
> Since my objects are used in windows applications as well as in web
> applications, I would like to determine in my lib class if she is serving a
> web or a windows application. Is there a neat way to detect this.
>
> Greets
>
> Jean.Paul
>
>
>
Author
21 Sep 2006 10:14 AM
Eliyahu Goldin
In most scenarios this will do:

/// <value>Indicates that the application is running in ASP.NET</summary>

public static bool IsWeb

{

get {return System.Web.HttpContext.Current != null;}

}


--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]



Show quote
"Jean Paul Mertens" <ON7AMI@newsgroups.nospam> wrote in message
news:%23%23gctPV3GHA.2228@TK2MSFTNGP03.phx.gbl...
> Hello to all,
>
> I use a lib class to handle all my exeption errors ocured in my objects.
> Since my objects are used in windows applications as well as in web
> applications, I would like to determine in my lib class if she is serving
> a web or a windows application. Is there a neat way to detect this.
>
> Greets
>
> Jean.Paul
>
>
Author
22 Sep 2006 5:43 PM
sloan
I agree with this one.  (aka, Eliyahu's)

I use this one fairly often.

Keep in mind which namespace/assembly its in.


PS

You normally dont' need to post to 4 or more groups.




Show quote
"Eliyahu Goldin" <REMOVEALLCAPITALSeEgGoldD***@mMvVpPsS.org> wrote in
message news:eGcLg7V3GHA.4024@TK2MSFTNGP03.phx.gbl...
> In most scenarios this will do:
>
> /// <value>Indicates that the application is running in ASP.NET</summary>
>
> public static bool IsWeb
>
> {
>
> get {return System.Web.HttpContext.Current != null;}
>
> }
>
>
> --
> Eliyahu Goldin,
> Software Developer & Consultant
> Microsoft MVP [ASP.NET]
>
>
>
> "Jean Paul Mertens" <ON7AMI@newsgroups.nospam> wrote in message
> news:%23%23gctPV3GHA.2228@TK2MSFTNGP03.phx.gbl...
> > Hello to all,
> >
> > I use a lib class to handle all my exeption errors ocured in my objects.
> > Since my objects are used in windows applications as well as in web
> > applications, I would like to determine in my lib class if she is
serving
> > a web or a windows application. Is there a neat way to detect this.
> >
> > Greets
> >
> > Jean.Paul
> >
> >
>
>

AddThis Social Bookmark Button