Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How Can Library Code "know" it's hosting application type?

Reply
Thread Tools

How Can Library Code "know" it's hosting application type?

 
 
Smithers
Guest
Posts: n/a
 
      08-07-2007
I'm writing a code library that needs to be reused between a Windows Forms
application and and an ASP.NET Web application.

The library needs to do a couple of things differently depending on the type
of application the library has been loaded for.

What is a reliable and non-hacking way for the code to make that
determination (hosting application type)?

Using .NET 3.5

Thanks


 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      08-07-2007
Well, ASP.NET often has an HttpContext.Current, but note that
personally I find this a bit hacky. It also doesn't work for things
like WCF hosted in IIS. I generally prefer to use a provider model,
where-by those bits that depend on the architecture are abstracted
through an interface (with some mechanism to register and obtain the
provider); in the web app I register one provider (perhaps using an
HttpModule to configure via web.config), and in the client I register
another.

But I guess it depends on how big the change is...

Marc


 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      08-07-2007
Smithers,

One way I know of is to set a reference to System.Web.dll and then check
the static Current poperty of the HttpContext class. If this returns null,
then there is no HttpContext, and no ASP.NET. Of course, this is only
applicable if you are actually processing a page. Calling this outside of a
request pipeline in ASP.NET will still return null, so if you need this for
one-time initialization, you might have to look for another option.


--
- Nicholas Paldino [.NET/C# MVP]
- http://www.velocityreviews.com/forums/(E-Mail Removed)

"Smithers" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm writing a code library that needs to be reused between a Windows Forms
> application and and an ASP.NET Web application.
>
> The library needs to do a couple of things differently depending on the
> type of application the library has been loaded for.
>
> What is a reliable and non-hacking way for the code to make that
> determination (hosting application type)?
>
> Using .NET 3.5
>
> Thanks
>



 
Reply With Quote
 
Ralph
Guest
Posts: n/a
 
      08-07-2007

"Smithers" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm writing a code library that needs to be reused between a Windows Forms
> application and and an ASP.NET Web application.
>
> The library needs to do a couple of things differently depending on the

type
> of application the library has been loaded for.
>


You need to revisit your design. Those "couple of things" likely either
don't belong in the library or need to be "passed" by the client at the time
of use.

-ralph


 
Reply With Quote
 
Brian
Guest
Posts: n/a
 
      08-07-2007
In the past I had always checked the current process image name. If it was
"w3wp.exe" then I knew it was running under IIS. I suggest you also check
against "WebDev.WebServer.Exe" since this is what VS 2005 uses during
development. If I find either of these 2 I assume I'm running in a web
application - otherwise assume WinForms.

- Brian
"Smithers" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm writing a code library that needs to be reused between a Windows Forms
> application and and an ASP.NET Web application.
>
> The library needs to do a couple of things differently depending on the
> type of application the library has been loaded for.
>
> What is a reliable and non-hacking way for the code to make that
> determination (hosting application type)?
>
> Using .NET 3.5
>
> Thanks
>


 
Reply With Quote
 
Samuel R. Neff
Guest
Posts: n/a
 
      08-07-2007

It's also possible to run ASP.NET under Apache.

http://weblogs.asp.net/israelio/arch...11/424852.aspx

Although much less common.

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.



On Tue, 7 Aug 2007 11:09:33 -0500, "Brian" <(E-Mail Removed)>
wrote:

>In the past I had always checked the current process image name. If it was
>"w3wp.exe" then I knew it was running under IIS. I suggest you also check
>against "WebDev.WebServer.Exe" since this is what VS 2005 uses during
>development. If I find either of these 2 I assume I'm running in a web
>application - otherwise assume WinForms.
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Web Hosting, Reseller Hosting, and Dedicated Hosting!!!!!! teo1991 Ruby 0 04-02-2009 01:50 PM
Web Hosting, Reseller Hosting, and Dedicated Hosting!!!!!! ufi02 ASP .Net 0 03-27-2009 07:49 PM
ANN: Free Trac/Subversion hosting at Python-Hosting.com Remi Delon Python 0 01-19-2005 06:15 PM
US web hosting or UK web hosting comapnies? Bhoona Computer Support 3 03-04-2004 12:59 AM



Advertisments