是的。下面的類實現IHttpModule接口和寄存器以及在發生HttpRequestValidationException檢查之前觸發的事件。它檢查請求是否爲POST,並且「testinput」不爲空,然後HTML將其編碼。該類需要作爲httpModule在Web.config中註冊。
類...
using System;
using System.Collections.Specialized;
using System.Reflection;
using System.Web;
public class PrevalidationSanitizer : System.Web.IHttpModule
{
private HttpApplication httpApp;
public void Init(HttpApplication httpApp)
{
this.httpApp = httpApp;
httpApp.PreRequestHandlerExecute += new System.EventHandler(PreRequestHandlerExecute_Event);
}
public void Dispose() { }
public void PreRequestHandlerExecute_Event(object sender, System.EventArgs args)
{
NameValueCollection form = httpApp.Request.Form;
Type type = form.GetType();
PropertyInfo prop = type.GetProperty("IsReadOnly", BindingFlags.Instance
| BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
prop.SetValue(form, false, null);
if (httpApp.Request.RequestType == "POST" != null
&& httpApp.Request.Form["testinput"])
httpApp.Request.Form.Set("testinput"
, httpApp.Server.HtmlEncode(httpApp.Request.Form["testinput"]));
}
}
的web.config項...
<system.web>
<httpModules>
<add type="PrevalidationSanitizer" name="PrevalidationSanitizer" />
...
這是張貼我沒有控制數據的應用程序。我打算將整個供應商應用程序從asp轉換爲aspx。我正在等待迴應,希望我能夠改變表格行動,但我不確定這個部門的靈活性。 – Dave 2009-06-29 14:13:03