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

我有一个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)]放在下面,我记得这些都是从上到下执行的。

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....