在 ASP MVC 5 项目中,RequestVerificationToken 未识别/或由 JMeter 分配给变量 [英] RequestVerificationToken is not idetifying/or getting assigned to variable by JMeter in a ASP MVC 5 Project

查看:38
本文介绍了在 ASP MVC 5 项目中,RequestVerificationToken 未识别/或由 JMeter 分配给变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前需要对 Web 解决方案进行负载测试,这需要在主页(欢迎页面)中进行用户身份验证.

当我在 FireFox 中使用 FireBug 寻找与登录凭据一起传递的 POST SignIn 参数时,我发现 Password、TenantName、UserName、__RequestVerificationToken 是与成功登录的值一起传递的参数.

I am currently in a need of a Load test for a web-solution, which requires for a user authentication in Homepage (Welcome Page).

When I seek for the POST SignIn parameters which are passing along with the login credentials using FireBug in FireFox, i found out that Password, TenantName, UserName, __RequestVerificationToken are the parameters which are passing along with their values for a successful login.

我需要使用 JMETER 来模拟这个过程.

I needed to simulate this process using the JMETER.

因此,我使用 JMETER 进行了 HTTP 请求(访问登录页面)以导航到该页面,该页面成功运行.

Therefore i have made a HTTP REQUEST (Visit Login Page) to Navigate to the page using JMETER, which successfully work.

在 HTTP 请求(访问登录页面)中,我添加了一个正则表达式提取器来提取令牌,因为需要将令牌与登录一起传递.

Within the HTTP REQUEST (Visit Login Page) I have added a Regular Expression Extractor, to Extract the token, since it is necessary to pass the token along with the sign in.

  • 参考名称:REQUEST_VERIFICATION_TOKEN
  • Reg 表达式:输入名称="__RequestVerificationToken" type="hidden" value="([A-Za-z0-9+=/- _]+?)"
  • 模板:$1$
  • 比赛编号:1
  • 默认值:(空白)

并且我添加了一个单独的 HTTP 请求(登录到 Web)以及参数,如下所示;

And I have added a separate HTTP Request (Login to Web) for signin along with the Parameters as follows;

  • 密码:${Password}
  • 租户名称:${租户名称}
  • 用户名:${用户名}
  • __RequestVerificationToken : ${REQUEST_VERIFICATION_TOKEN}

但是当我运行它时,在查看结果树下,响应数据生成为无法解密防伪令牌..."

But When I Run it, under the View Results Tree, the Response Data is generating as "The anti-forgery token could not be decrypted..."

当我检查查看结果树下的请求显示时,它显示为

POST数据:
密码=123456&TenantName=tenant&Username=admin&__RequestVerificationToken=%24%7BREQUEST_VERIFICATION_TOKEN%7D*

When i check for the Request displays under View Result Tree, it displays as

POST data:
Password=123456&TenantName=tenant&Username=admin&__RequestVerificationToken=%24%7BREQUEST_VERIFICATION_TOKEN%7D*

在请求中我意识到 RequestVerificationToken 的值没有被初始化.

Where in the Request I realized the value for the RequestVerificationToken is not getting initialized.

这两天我一直在通过博客寻找解决方案,最终在没有适当帮助的情况下,我倾向于将这个问题发布到这里.

I was searching for a solution through blogs for two days, where ultimately without a proper assistance I tend to post this question over here.

这是一个参考链接,在一定程度上很有用,我从中使用了:
http://build-failed.blogspot.com/2012/07/load-testing-aspnet-mvc-part-3-jmeter.html?showComment=1417672985397#c6427302313332055578

This is one reference link which is usefully for a extent, from which i used :
http://build-failed.blogspot.com/2012/07/load-testing-aspnet-mvc-part-3-jmeter.html?showComment=1417672985397#c6427302313332055578

有人可以帮助我了解为什么 RequestVerificationToken 没有正确提取或初始化为变量吗?

Can someone assist me of Why the RequestVerificationToken is not extracting properly, or getting initialized to the variable?

(Ps:老实说,当您提供宝贵的回复时,请假设我是 JMeter 的初学者)

( Ps : please be kind enough to assume that I'm a beginner in JMeter, to be honest, when you are providing your precious reply )

推荐答案

在正则表达式中'-'有含义&如果您的 __RequestVerificationToken 值中需要它,则必须正确转义它.

In Regular expression '-' has a meaning & it has to be escaped properly if it is expected in your __RequestVerificationToken value.

所以,正确的正则表达式应该是

So, the correct regular expression would be

input name="__RequestVerificationToken" type="hidden" value="([A-Za-z0-9+=/-\_]+?)"

我创建了一个临时变量 &以上正则表达式验证.它工作正常.如果它不适合您,请尽可能提供 HTTP 响应.

I created a temp variable & verified above regular expression. It works fine. If it does not work for you, Please provide the HTTP response if possible.

这篇关于在 ASP MVC 5 项目中,RequestVerificationToken 未识别/或由 JMeter 分配给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆