我有一个wmd编辑器的表单。输入文本区域使用:
- <%: 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”,但是它仍在发生。
有任何想法吗?
编辑
行动方式:
- [ILFFAuthorize(Roles = "Admin")] // this is a custom auth attrobite
- [HttpPost]
- [ValidateInput(false)]
- public ActionResult AddNews(FormCollection col){
- //public ActionResult AddNews(News news)
- //{
- if (ModelState.IsValid)
- {
- News news = new News();
- news.NewsDate = DateTime.Now;
- news.NewsPosterId = 0;
- news.NewsTitle = col["NewsTitle"];
- news.NewsBody = col["NewsBody"];
- newsRepository.Add(news);
- newsRepository.Save();
- return RedirectToAction("Index","Home");
- }
- else
- {
- return View();
- }
- }
解决方法
你需要把它放在你的[HttpPost]动作方法之上
- [HttpPost]
- [ValidateInput(false)]
- public ActionResult Edit(FormCollection collection) {
- .....
- }
如果你使用MVC3,那么你不应该使用[ValidateInput(false)],而是使用[AllowHtml],这里说明的是:http://dailydotnettips.com/2011/08/24/how-to-allow-user-to-input-html-in-asp-net-mvc/
还有:尝试将[HttpPost]上面的[ValidateInput(false)]放在下面,我记得这些都是从上到下执行的。