DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Tue, 7 Aug 2007 07:42:13 -0700,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Smithers
          2    Nicholas Paldino [.NET/C# MVP]
          3    Marc Gravell


How Can Library Code "know" it's hosting application type?   
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
Date:Tue, 7 Aug 2007 07:42:13 -0700   Author:  

Re: How Can Library Code "know" it's hosting application type?   
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]
          - mvp@spam.guard.caspershouse.com

"Smithers"  wrote in message 
news:emfthEQ2HHA.5160@TK2MSFTNGP05.phx.gbl...

> 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
> 
Date:Tue, 7 Aug 2007 10:51:44 -0400   Author:  

Re: How Can Library Code "know" it's hosting application type?   
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
Date:Tue, 7 Aug 2007 15:49:09 +0100   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us