Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在asp.net中转义内联代码块?_C#_Asp.net - Fatal编程技术网

C# 在asp.net中转义内联代码块?

C# 在asp.net中转义内联代码块?,c#,asp.net,C#,Asp.net,我的网站上有以下html: <meta name="keywords" content="<%=Keywords%>"/> <meta name="description" content="<%=Description%>"/> 我的想法是,我网站上的所有页面都将有一个默认的描述/关键字,除非我需要在特定页面上将它们设置为其他内容(使用Master.description=“where”) 但是,我遇到了一些问题:内联代码块增量的左括号在生成的

我的网站上有以下html:

<meta name="keywords" content="<%=Keywords%>"/>
<meta name="description" content="<%=Description%>"/>
我的想法是,我网站上的所有页面都将有一个默认的描述/关键字,除非我需要在特定页面上将它们设置为其他内容(使用
Master.description=“where”

但是,我遇到了一些问题:内联代码块增量的左括号在生成的HTML中转义,因此代码块不起作用。以下是为我的页面生成的html的摘录:

<meta name="keywords" content="&lt;%=Keywords%>" /><meta name="description" content="&lt;%=Description%>" />


我习惯于使用C#,但我对asp.net还不熟悉,我无法制定正确的语法使其正常工作。要使内联代码块正常工作,我需要做什么?

在服务器端运行控件并在那里赋值:

    <meta name="keywords" id="keywords" runat="server" />
    <meta name="description" id="desc" runat="server" />

    keywords.Attributes("content") = Keywords;
    desc.Attributes("content") = Description;

关键词。属性(“内容”)=关键词;
描述属性(“内容”)=描述;

在服务器端运行控件并在其中分配值:

    <meta name="keywords" id="keywords" runat="server" />
    <meta name="description" id="desc" runat="server" />

    keywords.Attributes("content") = Keywords;
    desc.Attributes("content") = Description;

关键词。属性(“内容”)=关键词;
描述属性(“内容”)=描述;

使用简单/单一绑定表达式

<meta name="keywords" content="<%# Keywords%>"/>
<meta name="description" content="<%# Description%>"/>

使用简单/单一绑定表达式

<meta name="keywords" content="<%# Keywords%>"/>
<meta name="description" content="<%# Description%>"/>

使用母版页很困难,因为子页看不到关键字和描述元素。通过母版页上的属性将对这些元素的所有更改集中在一起,我可以轻松地添加前缀/后缀。您可以将代码放在母版页代码后面。母版页代码隐藏文件将能够读取与母版页标记文件相同的对象,如果您有任何效率或类似的原因,可以这样做,而不是使用属性?我可以通过执行
get{return“\”+\u description+“\”}
来回避我的问题,但我想知道如何在不转义的情况下将内联代码块放在页面上。使用母版页很困难,因为子页看不到关键字和描述元素。通过母版页上的属性将对这些元素的所有更改集中在一起,我可以轻松地添加前缀/后缀。您可以将代码放在母版页代码后面。母版页代码隐藏文件将能够读取与母版页标记文件相同的对象,如果您有任何效率或类似的原因,可以这样做,而不是使用属性?我可以通过执行
get{return“\”“+\u description+“\”“}
来回避我的问题,但我想知道如何在页面上这样放置内联代码块而不转义它们。