Is there an #IF DEBUG for Asp.net markup?

前端 未结 5 1428
野的像风
野的像风 2020-12-05 17:07

Can I do something like this in the markup of an asp.net page, based off the \"Define DEBUG constant\" setting?

#IF (DEBUG) THEN
  

        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-05 18:09

    If you are trying to step through javascript or prefer to minify javascript when not debugging, I prefer this approach:

    <% if (Debugger.IsAttached) { %>
    
      
    
    <% } else { %>
    
      
    
    <% } %>
    

    I can easily step through code when I am debugging, otherwise I want the scripts to be minified. Be sure to include the following import:

    <%@ Import Namespace="System.Diagnostics" %>
    

    Moreover, it is nice to use the Web Essentials visual studio extension to bundle/minify your javascript files so that there is only one request made to the server for your scripts.

提交回复
热议问题