asp.net mvc 5 关闭xss过滤

在控制器方法的头部添加        [ValidateInput(false)]

如果向mvc服务端提交带html标签的内容就会导致校验失败异常,从而得不到想要的结果,关闭的方法是在相应方法头部添加 [ValidateInput(false)]属性。

如:

        [ValidateInput(false)]
        public ActionResult SendMail(string title, string[] shoujian, string content, HttpPostedFileBase file)
        {
            string sessionId = Request.Cookies["sessionId"]?.Value ?? "";
            if (string.IsNullOrEmpty(sessionId))
            {
                return Redirect("/login/index");
            }
            SaveMail(title,shoujian,content,file,false,sessionId);
            return Content("ok");
        }

 

posted on 2018-02-19 08:59  axel10  阅读(675)  评论(1编辑  收藏  举报