ASP.net VB.net code to see if site is published

Murray Brown
Murray Brown used Ask the Experts™
on
Hi. In ASP.net what VB.net 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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
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

      Else

            ' Assume we aren't running from the IDE

      End If

Open in new window

Chinmay PatelChief Technology Ninja
Distinguished Expert 2018
Commented:
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: https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/directives/if-then-else-directives

Here is a sample code:
   #If DEBUG Then
'DEBUG Mode Code Goes Here
   #Else
'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).

Regards,
Chinmay.
Murray BrownASP.net/VSTO Developer

Author

Commented:
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