在控制器方法的头部添加 [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"); ???????}
asp.net mvc 5 关闭xss过滤
原文地址:https://www.cnblogs.com/axel10/p/8453501.html