English 中文(简体)
在C#中插入数据库的栏目,并检索
原标题:Insert html tag to a Database as a String and retrieve it back in C#

我想将“html”插入一个数据库,作为“努力”取回。 在取回后,我想把它装在Grid。

例如

String word = "<h1>This is Heading </h1> <h2>This is body</h2> This is after tab";

在我对电网进行约束之后,它应当

<编码> 标题(大小)

<编码> 该机构(小体)——(表层) 表格

However this way is not working. It shows <h1>This is Heading </h1> <h2>This is body</h2> This is after tab word instead of applying real HTML behavior. I tryout with special character removal but it remain same result.

Please help me.

最佳回答

你们使用什么控制? 他们中的多数人将像你那样逃出html,并且要把财产写给你们。

如果你重新使用GredView,你就可以将HtmlEncode on在你的BoundColumn上伪造。

http://msdn.microsoft.com/en-us/library/system.web.ui.web Controls.stricfield.htmlencode.aspx

如果您重新使用“自动聚合物”栏目,见这一SO thread:。 防止自动生成的GredView栏中的超文本编码

问题回答

沉积到非行并不是一个问题,你可以直接将脚踏入行,在显示你必须使用<代码>HttpUyility.HtmlEncode()时,否则将邀请Javascript Hacking。

但是,如果你从网上获取数据,就能够确保数据的有效性得到撤销。 否则,你就会发现XSS的文字攻击错误。

you can bind your text in literal control it will represent the actual HTML formatted text. like :

ltrlMsg.Text="<div class="Message Success"> Your Message has been sent successfully! </div>"

或你也可以在你电网中约束。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签