我试着谷歌搜索了解它,但找到了同样错误的不同答案让我更加困惑.
Exception caught in Global.asax:System.Web.HttpRequestValidationException (0x80004005): A potentially dangerous Request.Form value was detected from the client (ctl00$MainContent$WarningCtl1$TXTWarningText=”
This is the warni…”).
at System.Web.HttpRequest.ValidateString(String value,String collectionKey,RequestValidationSource requestCollection)
at System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc,RequestValidationSource requestCollection)
at System.Web.HttpRequest.get_Form()
at System.Web.HttpRequest.get_HasForm()
at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull)
at System.Web.UI.Page.DeterminePostBackMode()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.app_config_appttypes_groupappttypes_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)
请建议.
解决方法
[ValidateInput (false)] public class MyController : Controller { ... }
或者你的行动方法:
public class MyOtherController : Controller { [ValidateInput (false)] public ActionResult MyActionMethod (MyObjectThatTakesInHtml myObject) { ... } }
编辑
正如@dotjoe指出的那样,我忘了提及,您还可以访问模型中属性的AllowHtmlAttribute(在System.Web.Mvc中找到).
public class MyObjectThatTakesInHtml { [AllowHtml] public string MyHtmlProperty { get; set; } }