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

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – 检测到潜在的危险Request.Form值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个wmd编辑器的表单。输入文本区域使用:
  1. <%: Html.TextAreaFor(t => t.NewsBody,new{@class="wmd-panel",id="wmd-input"}) %>

每次提交表单我得到一个潜在的危险Request.Form值从客户端检测到

我尝试在action方法上设置[ValidateInput(false)],我尝试添加
< httpRuntime requestValidationMode =“2.0”/>到web.config,我已经在web.config中的pages指令中尝试了validateRequest =“false”,但是它仍在发生。

有任何想法吗?

编辑

行动方式:

  1. [ILFFAuthorize(Roles = "Admin")] // this is a custom auth attrobite
  2. [HttpPost]
  3. [ValidateInput(false)]
  4. public ActionResult AddNews(FormCollection col){
  5.  
  6. //public ActionResult AddNews(News news)
  7. //{
  8. if (ModelState.IsValid)
  9. {
  10. News news = new News();
  11. news.NewsDate = DateTime.Now;
  12. news.NewsPosterId = 0;
  13.  
  14. news.NewsTitle = col["NewsTitle"];
  15. news.NewsBody = col["NewsBody"];
  16. newsRepository.Add(news);
  17. newsRepository.Save();
  18.  
  19. return RedirectToAction("Index","Home");
  20. }
  21. else
  22. {
  23. return View();
  24. }
  25. }

解决方法

你需要把它放在你的[HttpPost]动作方法之上
  1. [HttpPost]
  2. [ValidateInput(false)]
  3. public ActionResult Edit(FormCollection collection) {
  4. .....
  5. }

如果你使用MVC3,那么你不应该使用[ValidateInput(false)],而是使用[AllowHtml],这里说明的是:http://dailydotnettips.com/2011/08/24/how-to-allow-user-to-input-html-in-asp-net-mvc/

还有:尝试将[HttpPost]上面的[ValidateInput(false)]放在下面,我记得这些都是从上到下执行的。

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