读书人

从客户端(InstalledFonts=quot;lt;brgt;Timeslt;

发布时间: 2012-10-25 10:58:57 作者: rapoo

【求助】从客户端(InstalledFonts="<br>Times<br>Helveti...")中检测到有潜在危险的 Request.QueryString
rt,我在使用书中的例子调试时,点击页面menent.aspx上的“提交”按钮后出现这个错误,我在D:\Program Files\Microsoft Visual Studio 8\Web\WebNewFileItems\web.config中加入了<!--
<Page validateRequest=false />
-->后还是不能解决。

以下是我的menent.aspx文件代码:
============================================================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>不同事件的处理方法!</title>
<script language="C#" runat="Server">
void AddBtn_Click(Object sender, EventArgs e)
{
if (AvailableFonts.SelectedIndex != -1)
{
InstalledFonts.Items.Add(new ListItem(AvailableFonts.SelectedItem.Value));
AvailableFonts.Items.Remove(AvailableFonts.SelectedItem.Value);
}
}

void AddAllBtn_Click(Object Sender, EventArgs e)
{
while (AvailableFonts.Items.Count !=0)
{
InstalledFonts.Items.Add(new ListItem(AvailableFonts.Items[0].Value));
AvailableFonts.Items.Remove(AvailableFonts.Items[0].Value);
}
}

void RemoveBtn_Click(Object sender, EventArgs e)
{
if (InstalledFonts.SelectedIndex != -1)
{
AvailableFonts.Items.Add(new ListItem(InstalledFonts.SelectedItem.Value));
InstalledFonts.Items.Remove(InstalledFonts.SelectedItem.Value);
}
}

void RemoveAllBtn_Click(Object sender,EventArgs e)
{
while (InstalledFonts.Items.Count != 0)
{
AvailableFonts.Items.Add(new ListItem(InstalledFonts.Items[0].Value));
InstalledFonts.Items.Remove(InstalledFonts.Items[0].Value);
}
}

void result(Object sender, EventArgs e)
{
string tmpStr;
tmpStr="<br>";

while (InstalledFonts.Items.Count != 0)
{
tmpStr = tmpStr + InstalledFonts.Items[0].Value + "<br>";
InstalledFonts.Items.Remove(InstalledFonts.Items[0].Value);
}

tmpStr = System.Web.HttpUtility.UrlEncode(tmpStr,System.Text.Encoding.UTF8);//原文为UrlEncodeToString,新版本的.net没有此方法,故改为UrlEncode
//Page.Navigate("result.aspx?InstalledFonts="+ tmpStr);
Page.Response.Redirect("result.aspx?InstalledFonts="+ tmpStr);
}
</script>
</head>
<body bgcolor="#ccccff">
<center>
<h3><<font face="Verdana">.NET->不同事件的处理方法!</font></h3>
</center>
<center>
<form action="menent.aspx" runat="Server">
<table>
<tr>
<td>现有字体</td>
<td><!-- Filler --></td>
<td>选择的字体</td>
</tr>
<tr>
<td>
<asp:listbox id="AvailableFonts" width="100px" runat="Server">
<asp:listitem>Roman</asp:listitem>
<asp:listitem>Arial Black</asp:listitem>
<asp:listitem>Garamond</asp:listitem>
<asp:listitem>Somona</asp:listitem>
<asp:listitem>Symbol</asp:listitem>


</asp:listbox>
</td>
<td><!-- Filler --></td>
<td>
<asp:listbox id="InstalledFonts" width="100px" runat="Server">
<asp:listitem>Times</asp:listitem>
<asp:listitem>Helvetica</asp:listitem>
<asp:listitem>Arial</asp:listitem>
</asp:listbox>
</td>
</tr>
<tr>
<td>
<!-- Filler -->
</td>
<td>
<asp:button text="<<==" OnClick="RemoveAllBtn_Click" runat=server/>
<asp:button text="<--" OnClick="RemoveBtn_Click" runat=server/>
<asp:button text="-->" OnClick="AddBtn_Click" runat=server/>
<asp:button text="==>>" OnClick="AddAllBtn_Click" runat=server/>
<asp:label id="Message" forecolor="red" font-bold="true" runat=server/>
</td>
</tr>
<tr align=center>
<td align=center>
<asp:button text="提交" Onclick="result" runat=server/> <!-- Filler -->
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
=============================================================

以下是跳转的页面result.aspx

=============================================================


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>多事件处理结果页面</title>
<script language="C#" runat="Server">
void Page_Load(Object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
NameLabel.Text = Request.Params["InstalledFonts"];
}
}
</script>
</head>
<body>
<h3><font face="Verdana">.NET->多事件处理!</font></h3>
<p></p>
<p></p>
<hr />
<form action="controls_NavigationTarget.aspx" runat="Server">
<font face="Verdana">
Hi, 你的选择是:<asp:label id="NameLabel" runat="Server" />!
</font>
</form>
</body>
</html>

============================================================

以下是点击“提交”按钮后报错的页面

==============================================================

“/”应用程序中的服务器错误。
--------------------------------------------

从客户端(InstalledFonts="<br>Times<br>Helveti...")中检测到有潜在危险的 Request.QueryString 值。
说明: 请求验证过程检测到有潜在危险的客户端输入值,对请求的处理已经中止。该值可能指示危及应用程序安全的尝试,如跨站点的脚本攻击。通过在 Page 指令或 配置节中设置 validateRequest=false 可以禁用请求验证。但是,在这种情况下,强烈建议应用程序显式检查所有输入。

异常详细信息: System.Web.HttpRequestValidationException: 从客户端(InstalledFonts="<br>Times<br>Helveti...")中检测到有潜在危险的 Request.QueryString 值。

源错误:

只有在调试模式下进行编译时,生成此未处理异常的源代码才会显示出来。若要启用此功能,请执行以下步骤之一,然后请求 URL:

1. 在产生错误的文件的顶部添加一条“Debug=true”指令。例如:

<%@ Page Language="C#" Debug="true" %>

或:

2. 将以下的节添加到应用程序的配置文件中:

<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>

请注意,第二个步骤将使给定应用程序中的所有文件在调试模式下进行编译;第一个步骤仅使该特定文件在调试模式下进行编译。

重要事项: 以调试模式运行应用程序一定会产生内存/性能系统开销。在部署到生产方案之前,应确保应用程序调试已禁用。



堆栈跟踪:


[HttpRequestValidationException (0x80004005): 从客户端(InstalledFonts="<br>Times<br>Helveti...")中检测到有潜在危险的 Request.QueryString 值。]
System.Web.HttpRequest.ValidateString(String s, String valueName, String collectionName) +8736874
System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, String collectionName) +111
System.Web.HttpRequest.get_QueryString() +129
System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +65
System.Web.UI.Page.DeterminePostBackMode() +63
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
System.Web.UI.Page.ProcessRequest() +80
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP._01web页面_result_aspx.ProcessRequest(HttpContext context) +4
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75


=========================================================

请高手帮忙查看此问题如何解决,web.config我在机器上找到许多个,因为我机器上装了好几个版本的VS。但我只改了D:\Program Files\Microsoft Visual Studio 8\Web\WebNewFileItems目录下的。也不知道是不是改这个。希望路过的大侠指点一下,web.config具体要修改哪一个,这个文件有什么作用? 谢谢了。。

[解决办法]
<httpRuntime requestValidationMode="2.0"/>
加载 web.config里 这个是全局的

如果是单页面的话就在单页面文件顶头@page里 添上ValidateRequest="false"


[解决办法]
ls正解
[解决办法]
老问题了,自己看:
http://topic.csdn.net/u/20120405/12/01931693-afa6-482d-956a-b5d8f9099e60.html

读书人网 >asp.net

热点推荐