Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6323493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:31:44+00:00 2026-05-24T16:31:44+00:00

I have a code library that works in ASP.NET, the SQL CLR, and stand-alone

  • 0

I have a code library that works in ASP.NET, the SQL CLR, and stand-alone applications, and provides different features based on whether certain namespaces (such as System.Drawing) are available or not. Right now, I’m excluding those pieces of code manually, but it would be beneficial to have the C# compiler to it:

  • I could be lazier,
  • I could use one and the same library.

I know I can use #if directives to search for defines, and I could manually define something like ASP_NET, but if there’s a way to do this automatically, that’d be even greater.

So, can I detect ASP.NET? Alternatively, can I detect whether certain referenced assemblies are available?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:31:44+00:00Added an answer on May 24, 2026 at 4:31 pm

    There is no such predefined pre-processor directive for asp.net.

    What most people do is look for the current HttpContext – the assumption being that if it is null, this is not a web context.

    Another alternative is testing HttpRuntime.AppDomainAppId for null, to the similar assumption.

    Other similar options:

    System.Web.Hosting.HostingEnvironment.IsHosted == true
    System.Web.HttpRuntime.Cache != null
    

    And you can check that a web.config file exists.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have Flex applications that connect to our ASP.NET 3.5 Web Applications and usually
Suppose you have 2 different ASP.NET applications in IIS. Also, you have some ASCX
I have an ASP.NET MVC (using the release candidate) application that works with a
I have this small code library that I'm considering releasing into Open Source. I
I have a class, which is part of a code library project that was
We have a Library Project that we use for all our central reused code
I have a need to create a library of Object Oriented PHP code that
I have created a class library in VB .NET. Some code in the library
Background: I've wrote a small library that is able to create asp.net controls from
I have an ASP.NET MVC application which is using Linq to SQL classes placed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.