MVC2.0.net中的ValidateRequest=false

MVC2.0.net中的ValidateRequest=false,.net,asp.net-mvc,model-view-controller,.net,Asp.net Mvc,Model View Controller,我想在ASP.NET MVC 2.0中对特定视图禁用RequestValidation。因此,我添加了一些必要的查看页面指令部分,如下所示: <%@ Page ValidateRequest="false" Language="C#" MasterPageFile="Path" Inherits="System.Web.Mvc.ViewPage<Path>" %> 但还是不行 甚至尝试将其添加到Web.Config中: <httpRuntime request

我想在ASP.NET MVC 2.0中对特定视图禁用RequestValidation。因此,我添加了一些必要的查看页面指令部分,如下所示:

<%@ Page ValidateRequest="false" Language="C#" MasterPageFile="Path" Inherits="System.Web.Mvc.ViewPage<Path>" %>

但还是不行

甚至尝试将其添加到Web.Config中:

<httpRuntime requestValidationMode="2.0" />


您是否也在操作上添加了
[ValidateInput(false)]
属性?

我使用了此方法,因为这是我发现它工作的唯一方法

我用有效字符替换了无效字符


exp)
strUrl=strUrl.Replace(&),“-”

为什么不为发回的对象创建一个视图模型呢。 您可以使用正则表达式来防止非法字符,如<和>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace Web.Models.ViewModels
{
    public class Account
    {
        public Guid Id { get; set; }

        [Required(ErrorMessage = "You have to enter this")]
        [StringLength(100, ErrorMessage = "Too much text")]
        [RegularExpression(@"^([a-zA-Z0-9_\-\.\s]+)", ErrorMessage = "Not allowed")]
        public string Firstname { get; set; 
     }
}