Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

How do I tell if I'm in Console or Web application?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mowie_X - 20 Mar 2006 15:35 GMT
Hi,

How do I tell from within code whether or not I'm in a web or console
application? I need to know because it determines which config file I
am going to access.

There has to be a way via AppDomain or Environment, but I'm just not
finding it.

Thanks
sloan - 20 Mar 2006 18:53 GMT
Try this:

  if ( null == System.Web.HttpContext.Current ) // Add a reference to
System.Web.dll
  { //Non Web Environment

  }
  else
  { //Web Environment

  }

It may be fudgy on the first page you load.  (Aka, when testing, you set a
start up page to something like "default.aspx".
I'm not 100% sure this is the case, I'm just suggesting to be aware of it.

> Hi,
>
[quoted text clipped - 6 lines]
>
> Thanks
Mowie_X - 21 Mar 2006 03:14 GMT
Thanks a bunch. I found a similar kludgey solution.  Using the
System.Diagnostics namespace.

I get the current process and try to get the MainWindowHandle.Title..
And then I see if it endswith "exe".  Won't for a web app (will be
blank).

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.