允许文本框中出现非法字符

发布于 2024-12-17 10:19:38 字数 135 浏览 1 评论 0原文

我创建了一个文本框供用户输入评论。因此,有时他们会复制应用程序中出现的错误,并将其与注释一起粘贴到文本框中。它可能包含非法字符(例如 ),但应该保存它,但我的 .aspx 不允许。我不知道如何处理这个问题。谢谢!

I have created a textbox for my users to enter their comments. So, sometimes they copy the error that has been raised in the application and paste in the textbox along with comments. It may include illegal characters (eg. </11>) but it should be saved but my .aspx is not allowing. I don't know how to handle this. thanks!

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

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

发布评论

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

评论(4

岁月流歌 2024-12-24 10:19:38

如果您希望用户编辑文本框并输入 html 标签,您可以通过

 <%@ Page validateRequest="false" ...>

或在整个应用程序的 web.config 中禁用此功能:

<system.web>
  <page validateRequest="false" />
</system.web>

请注意,如果没有此 ValidateRequest 属性,则该属性不存在
原因。当您更改其默认值时,将出现不安全的输入
公认。因此,您需要验证每个用户的输入
避免跨站点脚本攻击,例如插入恶意代码
JavaScript、ActiveX、Flash 或 HTML


另一种智能解决方案是通过用户编写的 JavaScript 文本进行替换,以确保验证安全。
<代码>< anyword> ,而不是 被认为是安全的!

function validateTxt() {
    $("textarea, input[type='text']").change(function () {
      html = $(this).val(); //get the value
      //.replace("a" , "b")  works only on first occurrence of "a"
      html = html.replace(/< /g, "<"); //before: if there's space after < remove
      html = html.replace(/</g, "< "); // add space after <
      $(this).val(html); //set new value
   });
}

$(document).ready(function () {
      validateTxt();
});

If you want user to edit TextBox and enter html tags you can disable this via

 <%@ Page validateRequest="false" ...>

or in the web.config for your entire application:

<system.web>
  <page validateRequest="false" />
</system.web>

Note that this ValidateRequest property is not existing without
reason. When you change its default value, insecure input will be
accepted. Because of that, you need to validate every user's input to
avoid cross-site scripting attacks, like inserting of malicious
JavaScript, ActiveX, Flash or HTML


Another smart solution is to replace via javascript text written by user to make it safe for validation.
< anyword> , instead of <anyword> is considered safe!

function validateTxt() {
    $("textarea, input[type='text']").change(function () {
      html = $(this).val(); //get the value
      //.replace("a" , "b")  works only on first occurrence of "a"
      html = html.replace(/< /g, "<"); //before: if there's space after < remove
      html = html.replace(/</g, "< "); // add space after <
      $(this).val(html); //set new value
   });
}

$(document).ready(function () {
      validateTxt();
});
旧街凉风 2024-12-24 10:19:38

我假设您正在谈论一条异常消息,例如“从客户端检测到潜在危险的 Request.Form 值...”,

这是正在执行的 asp.net 请求验证。可以在页面或站点级别禁用此功能,但这样做存在风险。

这是通过页面指令或 web.config 中的 ValidateRequest="false" 完成的。

更多信息请参见:
http://www.asp.net/learn/whitepapers/request-validation

i assume you are talking about an exception message like "A potentially dangerous Request.Form value was detected from the client..."

that is the asp.net request validation in action. this can be disabled at the page or site level, but there are risks associated with doing so.

it is done with ValidateRequest="false" in the page directive or in web.config.

more information here:
http://www.asp.net/learn/whitepapers/request-validation

时光病人 2024-12-24 10:19:38

您可以尝试在传输之前对内容进行 Base64 编码。但我不确定我的解决方案是否真的很好。

http://nolovelust.com/post/classic-asp-base64-encoder -解码器.aspx

You can try to encode the content in Base64 before transferring it. But i'm not sure my solution is really good.

http://nolovelust.com/post/classic-asp-base64-encoder-decoder.aspx

书信已泛黄 2024-12-24 10:19:38

这可能是由于出于安全预防措施 HTML 被服务器端拒绝。

您可以通过以下任一方式禁用此检查:

将以下属性添加到页面标题 <%@ Page validateRequest="false" %>

或在 Web.Config 中进行更改应用程序范围

<configuration>
   <system.web>
      <pages validateRequest="false" />
   </system.web>
</configuration>

It could be due to the HTML being rejected server-side, as a security precaution.

You can disable this check by either:

Adding the following attribute to the page header <%@ Page validateRequest="false" %>

or making the change application wide in the Web.Config:

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