Asp.net 使用WCAT负载测试解决ValidateAntiForgeryTokenAttribute()问题

Asp.net 使用WCAT负载测试解决ValidateAntiForgeryTokenAttribute()问题,asp.net,asp.net-mvc,testing,wcat,Asp.net,Asp.net Mvc,Testing,Wcat,我正在使用WCAT对ASP.NET MVC应用程序执行负载测试。由于此应用程序使用防伪令牌安全验证,我想知道是否有可能在WCAT脚本值中动态生成postdata值,以便在每次获得防伪cookie值时注入有效令牌 有什么想法吗?提前感谢。我相信这是可以做到的,但我不知道有什么方法可以编写一个WCAT事务脚本,从而生成一个有效的防伪令牌 相反,我所做的是实现一个条件过滤器,将ValidateAntiForgeryTokenAttribute()应用于我的所有POST操作。设置好条件过滤器后,可以添加

我正在使用WCAT对ASP.NET MVC应用程序执行负载测试。由于此应用程序使用防伪令牌安全验证,我想知道是否有可能在WCAT脚本值中动态生成postdata值,以便在每次获得防伪cookie值时注入有效令牌


有什么想法吗?提前感谢。

我相信这是可以做到的,但我不知道有什么方法可以编写一个WCAT事务脚本,从而生成一个有效的防伪令牌

相反,我所做的是实现一个条件过滤器,将ValidateAntiForgeryTokenAttribute()应用于我的所有POST操作。设置好条件过滤器后,可以添加AppSettings值,该值允许您打开/关闭属性。i、 e.当您进行负载测试时,请将其关闭

您可以学习如何实现条件过滤器

在我的项目中,我在Global.asax.cs应用程序_Start()中启用和禁用条件筛选器,如下所示:

bool useAntiForgeryToken = string.Compare(ConfigurationManager.AppSettings["useAntiForgeryToken"], "true", StringComparison.InvariantCultureIgnoreCase) == 0;
if (useAntiForgeryToken) {

    // Ensure that all POST actions are automatically decorated with the ValidateAntiForgeryTokenAttribute.
    IEnumerable<Func<ControllerContext, ActionDescriptor, object>> conditions =
        new Func<ControllerContext, ActionDescriptor, object>[] {
        (controllerContext, actionDescriptor) =>
            string.Equals(controllerContext.HttpContext.Request.HttpMethod, "POST", StringComparison.OrdinalIgnoreCase ) ? new ValidateAntiForgeryTokenAttribute() : null
    };

    // Create the conditional filter using the condition we defined
    var provider = new ConditionalFilterProvider(conditions);

    // And add the conditional filter
    FilterProviders.Providers.Add(provider);
}
bool UseAnformeryToken=string.Compare(ConfigurationManager.AppSettings[“UseAnformeryToken”],“true”,StringComparison.InvariantCultureIgnoreCase)==0;
如果(使用AntiforgeryToken){
//确保所有POST操作都自动使用ValidateAntiForgeryTokenAttribute修饰。
不可数条件=
新函数[]{
(controllerContext,actionDescriptor)=>
string.Equals(controllerContext.HttpContext.Request.HttpMethod,“POST”,StringComparison.OrdinalIgnoreCase)?新建ValidateAntiForgeryTokenAttribute():null
};
//使用我们定义的条件创建条件过滤器
var provider=新的条件过滤器provider(条件);
//并添加条件过滤器
FilterProviders.Providers.Add(提供程序);
}
在我的web.config中有这样的应用程序设置:

<appSettings>
    <add key="useAntiForgeryToken" value="true">
</appSettings>
):


一旦你有了这些东西,再次运行你的WCAT脚本,你应该是黄金

<httpRuntime requestValidationMode="2.0">