, , . , - .
:
, :
public class UserInputValidator : BaseValidator
{
private HttpRequest Request
{
get { return HttpContext.Current.Request; }
}
protected override bool ControlPropertiesValid()
{
return true;
}
protected override bool EvaluateIsValid()
{
bool isValid = true;
var message = new StringWriter();
if (Request != null)
{
Request.ValidateInput();
NameValueCollection formValues = Request.Form;
foreach (string formKey in formValues.Keys)
{
try
{
#pragma warning disable 168
string formValue = formValues[formKey];
#pragma warning restore 168
}
catch (HttpRequestValidationException)
{
string orgValue = Request.Unvalidated.Form[formKey];
message.WriteLine("The following input is not allowed: {0}", HttpUtility.HtmlEncode(orgValue));
isValid = false;
}
}
}
ErrorMessage = message.ToString();
return isValid;
}
}
, , ValidateInput . , .
, , - ( , asp.net 4.5), .