加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 18:43:29 所属栏目:asp.Net 来源:网络整理
导读:我有一个wmd编辑器的表单。输入文本区域使用: %: Html.TextAreaFor(t = t.NewsBody,new{@class="wmd-panel",id="wmd-input"}) % 每次提交表单我得到一个潜在的危险Request.Form值从客户端检测到 我尝试在action方法上设置[ValidateInput(false)],我尝试添
我有一个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)]放在下面,我记得这些都是从上到下执行的。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读