code to see if site is published

Murray Brown
Murray Brown used Ask the Experts™
Hi. In what code would I use to see if the site has been published. I have to run slightly different code to what I run in debug mode.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
it can be debugged even if published.. if you want things to act differently when attached to the debugger
  If Debugger.IsAttached Then

            ' Since there is a debugger attached,

            ' assume we are running from the IDE


            ' Assume we aren't running from the IDE

      End If

Open in new window

Chinmay PatelChief Technology Ninja
Distinguished Expert 2018
Hi Murray,

If you go to Web Application or Project properties, you will see there are multiple options available.
One of those Option is to set your project to Release Build or Debug Build. There is a huge difference in a Debug mode assembly and Release mode assembly in terms of Performance, Size and Debug Information database. This setting also drives your pre-processor directives.  

So if you really want to know if your application is in debug mode and want to alternate the code's behavior based on whether the code is generated in Debug mode or Release mode, ideally you should use Pre-Processor Directives or Directives. Please go through this article:

Here is a sample code:
   #If DEBUG Then
'DEBUG Mode Code Goes Here
'Release Mode Code Goes Here
   #End If

Open in new window

Another benefit of this method is that if by mistake you push debug build to server, you will immediately notice that this is a debug build (As on server, generally you will not have the option to attach the debugger).

Murray Developer


Thanks very much

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial