简体   繁体   English

仅C#HtmlEncode名称

[英]C# HtmlEncode name only

According to this table, I need to Encode a string in C# the following way: Only encode the characters that have an HTML Name, with their HTML Name from the table in the link (and the symbols that do NOT have HTML Name should stay the same and not replaced with their HTML Number ). 根据表,我需要通过以下方式在C#中对字符串进行编码:仅对具有HTML名称的字符进行编码,并在链接中使用表中的HTML名称(而没有HTML 名称的符号应保留为相同,而不是用其HTML 编号代替)。

for example: I want the string & ' to be encoded to & ' 例如:我希望将字符串& '编码为& ' & ' , but the results I am getting are giving & ' & ' ,但我得到的结果就是& ' & ' , it is converting a symbol that also does not have a HTML Name. ,它正在转换也没有HTML名称的符号。

HttpUtility.HtmlEncode();

is encoding to both HTML Name and HTML Number.. 被编码为HTML名称和HTML编号。

UPDATE: trying to use Microsoft.Security.Application.Encoder.HtmlEncode ( link ) is giving also the same encoding results. 更新:尝试使用Microsoft.Security.Application.Encoder.HtmlEncodelink )也给出了相同的编码结果。

Any suggestions for other solution? 对其他解决方案有什么建议吗?

Any suggestions for other solution or a way to implement Microsoft.Security;? 对其他解决方案或实现Microsoft.Security的方式有何建议?

Have you tried adding the System.Security dll manually? 您是否尝试过手动添加System.Security dll?

References folder in the solution, rightclick, Add Reference.., Assemblies, Framework, browse to System.Security, check the box and press OK. 在解决方案中的“引用”文件夹中,右键单击,“添加引用..”,“程序集”,“框架”,浏览到System.Security,选中此框,然后按“确定”。

Now you should be able to add: 现在您应该能够添加:

using System.Security

at the top of your C# file. 在C#文件的顶部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM