Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

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


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

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
 
Share this answer
 
Comments
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.
[no name] 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.
[no name] 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.
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:

C#
#if DEBUG

#else

#end if



do something like this:

C#
if (!HttpContext.Current.IsDebuggingEnabled)
{
    // Release
}
else
{
    // Debug
}
 
Share this answer
 
Comments
[no name] 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.
[no name] 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.
[no name] 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
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
HTML
#if DEBUG ... 
does not work! (Because it is compiled with
HTML
Debug=true
)
Please let me know if you think something else.
Thank you guys again.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900