473,382 Members | 1,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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
Aug 7 '07 #1
5 1336
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]
- mv*@spam.guard.caspershouse.com

"Smithers" <A@B.comwrote in message
news:em**************@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

Aug 7 '07 #2
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
Aug 7 '07 #3

"Smithers" <A@B.comwrote in message
news:em**************@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.
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
Aug 7 '07 #4
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" <A@B.comwrote in message
news:em**************@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
Aug 7 '07 #5

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" <br************@ishcm.com>
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.
Aug 7 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: DotNetMania | last post by:
do you know the word .... "zizzy" ? what is that mean? is it usually use? best regards..
13
by: Shi Jin | last post by:
Hi there, While I was trying to disassemble a simple C program for my OS course, I found that the call to function longjmp is actually called to siglongjmp under linux. And similarly, under...
1
by: Agnes | last post by:
I can't find any property about the "no of records" of datareader . I don't want to loop the datareader and use counter to count it. Any suggestion? Thanks
2
by: UJ | last post by:
I have a drop down list that I want to have when a certain value has been selected, another set of controls becomes visible. I've done it using radio buttons but I don't know how to do it with a...
4
by: Chris Curvey | last post by:
Hi all, I have used the win32com libraries to set up a service called MyService under Windows. So far, so good. Now I need to run multiple copies of the service on the same machine. I also...
5
by: Smithers | last post by:
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...
4
by: eBob.com | last post by:
If I type "objSheet." ("Dim objSheet As Excel._Worksheet") VS gives me a list of everything which can follow the period. Or so I have always thought. But recently I've needed the Pictures method...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.