在App.Config中使用哪种编码?

编程入门 行业动态 更新时间:2024-10-25 22:33:37
本文介绍了在App.Config中使用哪种编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

由于值中的& ,以下 config 文件导致错误:

Following config file causes error because of & in 'url' value:

<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key ="url" value ="www.example/?user=admin&password=1234"/> </appSettings> </configuration>

问题是 config 文件中的键/值使用哪种编码?(即网址编码...)

The question is which encoding to use for key/value in a config file ? (i.e Url Encoding ...)

推荐答案

这是一个XML文件.因此,您必须XML保留所有保留字符:

This is an XML file. As such, you must XML-escape all reserved characters:

<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key ="url" value ="www.example/?user=admin&amp;password=1234"/> </appSettings> </configuration>

通过编程,您可以使用 System.Web.HttpUtility.HtmlEncode 方法执行这种转义.是的,它的名字暗示了HTML特定的编码,但是以我的经验,这等同于XML的转义.

Programmatically you can perform this type of escaping using the System.Web.HttpUtility.HtmlEncode method. Yes, its name suggests HTML specific encoding, but in my experience this is equivalent to XML escaping.

更多推荐

在App.Config中使用哪种编码?

本文发布于:2023-11-08 13:30:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569503.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:哪种   App   Config

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!