[英]updating values in web.config
I need to store an escaped html string in a key in web.config using the KeyValueConfigurationElement.Save method built into framework 3.5. 我需要使用框架3.5中内置的KeyValueConfigurationElement.Save方法将转义的html字符串存储在web.config中的密钥中。 But when I try to do so, it keeps escaping my ampersands.
但是当我试图这样做的时候,它一直在逃避我的&符号。
Code looks like this: 代码如下所示:
strHTML = DecodeFTBInput(FTB1.Text)
FTB1.Text is a string of HTML, like this: <b><font color="#000000">Testing</font></b>
FTB1.Text是一个HTML字符串,如下所示:
<b><font color="#000000">Testing</font></b>
DecodeFTPInput uses the String.Replace() method to change < and > to <
DecodeFTPInput使用String.Replace()方法将<和>更改为
<
and >
和
>
, and " to "
. ,和“到
"
。
Given the above string and function, let's say strHTML
now contains the following: 鉴于上面的字符串和函数,让我们说
strHTML
现在包含以下内容:
<b><font color="#000000">Testing</font></b>
Of course I can manually edit web.config to store the correct value, but I need the authenticated admin user to be able to change the html themselves. 当然我可以手动编辑web.config来存储正确的值,但我需要经过身份验证的管理员用户才能自己更改html。
The problem is that when I try to save this string into its key in web.config, it escapes all ampersands as &
问题是,当我尝试将此字符串保存到web.config中的键时,它会将所有&符号转义为
&
which ruins the string. 哪个破坏了字符串。
How can I get around this? 我怎么能绕过这个?
web.config
is an XML file, so when it writes values there the .NET Framework stores strings using HTML encoding , replacing the <
>
&
characters with <
web.config
是一个XML文件,因此当它在那里写入值时,.NET Framework使用HTML编码存储字符串,将<
>
&
字符替换为<
, >
,
>
and &
和
&
, and much more besides. 等等。
You'll need to stop your DecodeFTPInput method from HTML encoding the string if you want the HTML in the web.config file to be editable. 如果希望web.config文件中的HTML可编辑,则需要从HTML编码字符串中停止DecodeFTPInput方法。 Otherwise you'll be HTML encoding twice, which isn't the result you want!
否则你将进行两次HTML编码,这不是你想要的结果!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.