[英]Textbox validation forcing error
Vista, visual web developer express 2010, c#, asp.net, webforms. Vista,可视化网络开发者快递2010,c#,asp.net,webforms。 Running program with ctrl-F5.
使用ctrl-F5运行程序。 I'm the only person who will ever run this program ... and it will only ever run on my laptop using a local database.
我是唯一一个会运行这个程序的人......它只会在我的笔记本电脑上使用本地数据库运行。
Writing app to download web pages, view them, (do some analysis), log some results. 编写应用程序来下载网页,查看它们,(做一些分析),记录一些结果。 I found code to download pages - works well.
我找到了下载页面的代码 - 效果很好。 I then set the text property of a textbox equal to the string contents of the page.
然后我将文本框的text属性设置为等于页面的字符串内容。 That part also works.
那部分也有效。 Then I went to run the code again, BUT the contents of the textbox gets validated and results in an error message.
然后我再次运行代码,但文本框的内容得到验证并导致错误消息。
A potentially dangerous Request.Form value was detected from the client (ctl00$MainContent$tbPageContents="
<!DOCTYPE HTML PUBLI...").
I can run the code over and over without problem - so long as I don't display the results in a textbox. 我可以反复运行代码而不会出现问题 - 只要我不在文本框中显示结果。 I tried a couple different solutions:
我尝试了几种不同的解决方案:
I tried enabled="false" attribute in the textbox ... this allows me to view the first part of the code, but since the textbox is not enabled, I can't scroll up and down and look at the file. 我在文本框中尝试了enabled =“false”属性...这允许我查看代码的第一部分,但由于文本框未启用,我无法上下滚动查看文件。 So this doesn't really solve the problem.
所以这并没有真正解决问题。
I tried setting validateRequest="false" in the page directive and in system.web (as per http://www.asp.net/learn/whitepapers/request-validation ), but so far as I can tell it has no effect. 我尝试在page指令和system.web中设置validateRequest =“false”(根据http://www.asp.net/learn/whitepapers/request-validation ),但据我所知,它没有效果。 That is, I still get the error.
也就是说,我仍然得到错误。
I tried using html encoding the string contents before I put them into the textbox. 在我将它们放入文本框之前,我尝试使用html编码字符串内容。 That works on the display ... but it doesn't fix the problem that it fails on the next iteration of the problem.
这可以在显示器上工作......但它不能解决它在下一次问题迭代时失败的问题。
I thought about catching the error and ignoring it, but the validation seems to happen before it executes my code-behind. 我想要捕获错误并忽略它,但验证似乎在它执行我的代码隐藏之前发生。
I don't actually HAVE to print the page to a window to do the analysis, but it would be very helpful if I could look at this stuff all at once or in snippets. 我实际上并不打算将页面打印到窗口进行分析,但如果我可以一次性或以片段形式查看这些内容,那将非常有用。 I could just do a page source from a browser.
我可以从浏览器中做一个页面源代码。 I'm not sure ... maybe that's the preferred solution.
我不确定......也许这是首选的解决方案。
I'm really surprised that option #2 did not work, as that seems to be the recommended solution. 我真的很惊讶选项#2不起作用,因为这似乎是推荐的解决方案。
Here's the page directive I use: 这是我使用的页面指令:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="wan._Default" validateRequest="false" %>
Is there something else one needs to do to stop the validateRequest? 是否还需要做一些其他事情才能停止validateRequest?
You should also use <httpRuntime requestValidationMode="2.0" />
in your web.config file. 您还应该在web.config文件中使用
<httpRuntime requestValidationMode="2.0" />
。 This instructs ASP.NET to change its validation mode to version 2.0. 这指示ASP.NET将其验证模式更改为2.0版。
You may also like to see this question . 您可能也想看到这个问题 。
如果这是.NET 4,您可能还需要将<httpRuntime requestValidationMode="2.0" />
到您的web.config中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.