1. 程式人生 > >asp.net mvc 5 關閉xss過濾

asp.net mvc 5 關閉xss過濾

turn urn ase action valid session 頭部 cti class

在控制器方法的頭部添加 [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過濾