"#if DEBUG" on an ASPX / ASCX page

I want to be able to specify one of two assemblies based on which mode (DEBUG or RELEASE) I selected in my VS2005 IDE. Something like this (which doesn't work):

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VideoDialog.ascx.cs" Inherits="Company.Web.Base.Controls.VideoDialog" %>

<% #if DEBUG %>
<%@ Register TagPrefix="Company" Assembly="Company" Namespace="Company.UI.Controls.VideoControl" %>
<% #else %>
<%@ Register TagPrefix="Company" Assembly="Company.UI.Controls.VideoControl" Namespace="Company.UI.Controls.VideoControl" %>
<% #endif %>

<Company:CompanyVideo ID="Video1" runat="server"></Company:CompanyVideo>

So my question is: how to use #if DEBUG on an ASPX or ASCX page?

+3
source share
3 answers

, , , . web.config, , web.config /debug. , web.config / ( debug = "true" ) , .

+3
<%
//<compilation debug="false"> in web.config
//*.aspx

#if DEBUG
    Response.Write("<script type=\"text/javascript\">");
    Response.Write("$.validator.setDefaults({ debug: true })");
    Response.Write("</script>");
#endif

%>
+3

HtmlHelper. # :

namespace ExtensionHandlers
{
    public static class MetaTags
    {
        public static string GetMetaTags(this HtmlHelper html)
        {
            #if DEBUG

            return string1;

            #else

            return string2;

            #endif
        }
    }
}

ascx :

<%@ Import Namespace="ExtensionHandlers" %>

, , , :

<%= Html.GetMetaTags() %>

: , , . .

+2

Source: https://habr.com/ru/post/1711302/


All Articles