我有一个用户控件,我正在传入一个查询字符串,.net 似乎认为这是危险的。我已经输入了我的网络.config
<httpRuntime requestValidationMode="2.0" enableVersionHeader="false" maxUrlLength="10999" maxQueryStringLength="2097151"/>
<security>
<requestFiltering>
<requestLimits maxUrl="10999" maxQueryString="2097151" />
</requestFiltering>
</security>
我的用户控件是:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Member.ascx.cs" Inherits="DOM.Umbraco.Web.usercontrols.Members" %>
但仍然没有希望..如何让它允许此查询字符串?
谢谢多姆
您可以使用
此 web.config 设置禁用请求验证
<configuration>
<system.web>
<pages validateRequest="false" />
</system.web>
</configuration>
考虑到根本没有验证可能会导致安全问题。您需要将内置验证替换为一些自定义代码,以清理来自客户端的数据。
如果希望仅将此设置限制为使用用户控件的页,则可以使用此页指令
<@ Page validateRequest="false" %>
覆盖请求验证器并允许您需要的字符。 请注意,如果要重新显示数据,它将包含原始内容,这可能是危险的。即脚本标签
public class CustomRequestValidator : System.Web.Util.RequestValidator
{
protected override bool IsValidRequestString(HttpContext context, string value, RequestValidationSource requestValidationSource, string collectionKey, out int validationFailureIndex)
{
validationFailureIndex = 0;
if (requestValidationSource == RequestValidationSource.Form)
{
value = value.Replace("<", "").Replace(">", "");
}
return base.IsValidRequestString(context, value, requestValidationSource, collectionKey, out validationFailureIndex);
}
}