使用小于/大于符号(< 和 >)填充文本框

发布于 2024-12-28 02:15:53 字数 280 浏览 2 评论 0 原文

所以我遇到了一些问题,在我正在开发的网站的各个部分中,我显示了一些包含 << 的日志。和>不同地点的符号。好吧,当我显示日志时它工作正常。当然,每当我离开时,我都会收到以下错误:

从客户端检测到潜在危险的 Request.Form 值...

现在我明白这是因为 <<和>是我得到的html特殊字符。但是,有什么方法可以禁用或以某种方式允许页面显示/处理这些内容吗?我知道我可以将这些角色从它们可能出现的任何地方删除,但如果不需要,我宁愿不这样做。

有什么建议吗?

so I've been running into some problems where in various parts of my website I'm developing, I'm displaying some logs that contain < and > symbols in various spots. Well when I display the log it works fine. Of course anytime I navigate away I get an error of:

A potentially dangerous Request.Form value was detected from the client ...

Now I understand it's because < and > are html special characters which I get. But, is there any way to disable or somehow allow the page to display / process those? I know I could strip those characters out of anyplace they may appear, but I'd rather not if I don't have to.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

掌心的温暖 2025-01-04 02:15:53

您没有发布任何代码,所以我假设您想要以下内容:

<textbox><</textbox>

这真的很简单,HTML 对您的内容进行编码:

<textbox><</textbox>

您可以使用 HttpUtility.HtmlEncode 来执行此操作。

You didn't post any code, so I will assume you want something along the lines of:

<textbox><</textbox>

It's simple really, HTML encode your content:

<textbox><</textbox>

You can use HttpUtility.HtmlEncode to do this.

梦幻的味道 2025-01-04 02:15:53

将“>”替换为“>”,将“<”替换为“<” >"

阅读 查看 HTML 特殊实体列表

Replace ">" with ">" and "<" with "<"

Read this see a list of HTMLs special entities

奢欲 2025-01-04 02:15:53

如果您只是希望 Web 应用程序允许表单输入包含潜在危险的字符,则可以通过几种方法来实现此目的,具体取决于框架。我自己主要使用 MVC,在控制器操作上使用 [ValidateInput(false)] 属性。

对于 WebForms,我将在此处引导您。 http://msdn .microsoft.com/en-us/library/ie/bt244wbb.aspx:)

If you simply want your web application to allow form input to contain potentially dangerous characters there are a few ways to do this depending on framework. I mostly use MVC myself, where you use the [ValidateInput(false)] attribute on your controller actions.

For WebForms, I'll direct you here instead.. http://msdn.microsoft.com/en-us/library/ie/bt244wbb.aspx :)

指尖凝香 2025-01-04 02:15:53

要回答您的问题,请将 ValidateRequest="false" 放入 <%@Page...

请小心,因为您现在负责防止脚本攻击

to answer your question put ValidateRequest="false" in <%@Page...

be careful, as you are now responsible for prevent script attacks

预谋 2025-01-04 02:15:53

我遇到了同样的错误,只需将文本框的属性“Enabled”设置为“false”即可解决。我猜这会阻止验证文本框的值。

在标签而不是文本框中显示文本也可以。

I encountered the same error and solved it simply by setting the property "Enabled" of the textboxes on "false". Guess this prevents the value of the textboxes being validated.

Displaying the texts in labels instead of textboxes also works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文