asp.net-mvc – 从客户端检测到潜在危险的Request.Form值

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – 从客户端检测到潜在危险的Request.Form值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在运行ASP.Net MVC应用程序并面临以下错误.由于我是ASP.Net的新手,有人可以帮助我,告诉我这是什么意思,我该如何解决

我试着谷歌搜索了解它,但找到了同样错误的不同答案让我更加困惑.

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)

请建议.

解决方法

您需要将ValidateInputAttribute添加到控制器(将其应用于该控制器的所有操作方法,因此请小心):
[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; }
}
原文链接:https://www.f2er.com/aspnet/247555.html

猜你在找的asp.Net相关文章