Click here to Skip to main content
12,998,277 members (61,080 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi guys,

I have a problem. I have a code something like this:
<% #if DEBUG 
  // Do Debug
  //Do Release

This code works fine on my visual studio. I mean when I change debug=true or false in web.config, I can get the result as desire. But when I publish the code on the server, It always return the release part! no matter debug is true or false.
Can any one please tell me what should I do to make it works?

Note: I publish my website with Visual Studio to the server with all checkboxes not selected. I mean "Allow this precompiled site to be updatable" and the other options are unchecked.
Posted 19-Oct-11 12:33pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

The #DEBUG pre-processor directive is added by VS. You can view this, and add your own via the properties page on the build tab -> Define DEBUG constant.

However, you SHOULD NOT be running debug code in a production environment. Period
Philippe Mori 19-Oct-11 22:50pm
Effectively... As much as possible, debugging should be done on local machine and if something does not works the same way, the best thing to do is first check with web site support and if you still don't know why it does not works the same way as locally, then deploy another application elsewhere (on the server) to do your debugging.
Mark Nischalke 19-Oct-11 22:57pm
What? Deploy another application on the same server to debug the first?
Philippe Mori 20-Oct-11 8:40am
The same application but compiled for DEBUG and installed elsewhere (not the address) ideally using its own database so that the OP can debug the application without affecting user that use the real application.
Mark Nischalke 20-Oct-11 8:52am
And how is that possibly a good idea or would even help solve the OPs problem?
Philippe Mori 20-Oct-11 10:09am
Because you should not debug an application in production use whenever possible to do it otherwise... For example, you don't want your user to see detailled error message that could occurs while running the application or extra text displayed for debugging purpose in the web page. Another possibility would be if users are authenticated, to have a role for debugging that only the OP would have and then output the information appropriatly for debugging but only when he is logged.
Mark Nischalke 20-Oct-11 13:20pm
Good luck with all of that. [roll eyes]
aidin Tajadod 21-Oct-11 14:54pm
Mark, I am working on a website and I could not find it. ( I think what you said is not correct for websites)
And thank you guys. I don't have a plan to run my website under Debug mode. But I found a bug on production which forced me to do some researches and had to run my website under debug mode to findout the problem.
Mark Nischalke 21-Oct-11 15:28pm
Yes, it is for websites also. You may not be looking correctly.
aidin Tajadod 21-Oct-11 16:55pm
I think you mean webproject! I could not find it in my website
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can do debugging checks in web projects by checking the httpcontext. Set the debugging="true" in web.config. When you want to check for debugging being enabled, then instead of wrapping up your code like this:

#end if

do something like this:

if (!HttpContext.Current.IsDebuggingEnabled)
    // Release
    // Debug
Mark Nischalke 19-Oct-11 22:22pm
Not the same thing as #DEBUG preprocessor
Philippe Mori 19-Oct-11 22:48pm
Maybe... but since pages are not recompiled on each request and since there is no place to put defines for the C# compiler on the web site, then that solution is probably the way to do something special if you need to debug something.
Mark Nischalke 19-Oct-11 22:55pm
No maybe about it. IsDebuggingEnabled IS NOT the same as the #DEBUG preprocessor command.
CodingLover 19-Oct-11 22:59pm
Yes, not exactly the same. But still we can achieve the same that Op is looking.
Mark Nischalke 19-Oct-11 23:16pm
No, you cannot achieve the same result since they are different features with different usages. If you believe otherwise then provide and example, perhaps an informative article explaining so
Philippe Mori 20-Oct-11 8:38am
Then the OP just have to compile the web application before deploying it... if he really want to use DEBUG define.
aidin Tajadod 21-Oct-11 14:57pm
Thank you CodingLover, Although it isn't not the same as #If ... but I learned something new.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Ok guys,
I think I found the problem,
When I uncheck "Allow this precompiled site to be updatable" while publishing the website, It means that I have puiblished the compiled codes for both pages and codebehinds. So all those compiler options now have been compiled. So changing the Debug to true or false, will not compile whole the website again. ( There is no code there to be compiled) and thus
#if DEBUG ... 
does not work! (Because it is compiled with
Please let me know if you think something else.
Thank you guys again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 21 Oct 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100