<和>保存到数据库时转换为HTML代码 [英] < and > converted to html code while saving into database

查看:847
本文介绍了<和>保存到数据库时转换为HTML代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我们在IIS 7中部署了一个.NET应用程序。在某些文本框中,如果我们输入特殊字符,例如< >或&,它转换为html代码为> <和&保存到数据库时。



但我们在差异服务器中有相同的代码,它工作正常。



可以解决的问题。



我们应该使用html编码器和解码器还是有任何IIS设置需要更改。



谢谢

解决方案

因为Ranjeet说它发生在代码中的某个地方,但通过使用HttpUtility,您可以解码它。这是一个例子:





 HttpUtility.HtmlEncode(<    > &); //结果& lt;  & gt;  & ; amp;  
HttpUtility.HtmlDecode(& lt; & gt; & amp;); //结果< > & ;


Hi,

We have one .NET application deployed in IIS 7. In certain text boxes if we enter special charaters like < > or &, it is converted to html code as > < and & while saving to database.

But we have the same code in diff server and it is working fine.

What can be the solution.

Should we use html encoder and decoder Or is there any IIS setting needs to be changed.

Thanks

解决方案

As Ranjeet said it has happened somewhere in your code , but by using the HttpUtility you can decode it. here is an example :


HttpUtility.HtmlEncode("< > &"); //result &lt; &gt; &amp;
        HttpUtility.HtmlDecode("&lt; &gt; &amp;"); //result < > &


这篇关于&LT;和&gt;保存到数据库时转换为HTML代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆