处理潜在危险的查询字符串

发布于 2024-11-24 08:37:15 字数 464 浏览 5 评论 0原文

我的项目实现搜索(从默认 HTML 页面)并将重定向到搜索页面(ASPX 页面),并且我使用查询字符串来传递搜索值。当语言设置为非英语(例如泰语、西里尔语)时,我收到潜在危险的Request.QueryString value服务器错误。

有什么办法可以从客户端处理这个问题吗?目前我无法找到从页面本身处理此问题的方法(Page_LoadPage_PreInit 未触发)。

这是我用于重定向的代码:

function Search()  {
    var searchString = document.getElementById('txtSearch').value;
    location.href = "/Search.aspx?search=" + searchString;
}

My project implements search (from default HTML page) and will redirect to the search page (ASPX page) and I'm using query string to pass the search value. I'm getting potentially dangerous Request.QueryString value server error when language is set to non-english (e.g. thai, cyrillic).

Is there any way to handle this from client side? Currently I can't find a way to handle this from the page itself (Page_Load, Page_PreInit isn't triggering).

Here's the code I used for redirecting:

function Search()  {
    var searchString = document.getElementById('txtSearch').value;
    location.href = "/Search.aspx?search=" + searchString;
}

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

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

发布评论

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

评论(2

茶花眉 2024-12-01 08:37:15

validateRequest="false" 添加到您的 .Net Page 或 Web.config 文件

,或者

您可以对您的 url 变量进行编码,添加 encodeURIComponent

function Search()  {
    var searchString = document.getElementById('txtSearch').value;
    location.href = "/Search.aspx?search=" + encodeURIComponent(searchString);
}

Adding validateRequest="false" to you .Net Page or Web.config file

OR

you can encode your url vars, adding encodeURIComponent:

function Search()  {
    var searchString = document.getElementById('txtSearch').value;
    location.href = "/Search.aspx?search=" + encodeURIComponent(searchString);
}
青萝楚歌 2024-12-01 08:37:15

如果您的数据看起来大致像代码,您可能必须禁用此验证;但是您需要真正确定您的代码处理,特别是避免 XSS 和 SQL 注入攻击。您应该能够在 aspx validateRequest=false 中设置以在每个页面上禁用:

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

或者如果您在任何地方都需要它,则可以在 web.config 中全局禁用。

If your data is going to look roughly like code you may well have to disable this validation; but then you need to be really sure about your code handling, in particular avoiding XSS and SQL injection attacks. You should be able to set in the aspx validateRequest=false to disable on a per-page basis:

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

or globally in the web.config if you need this everywhere.

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