JMeter在ASP MVC 5项目中没有对RequestVerificationToken进行识别/未将其分配给变量 [英] RequestVerificationToken is not idetifying/or getting assigned to variable by JMeter in a ASP MVC 5 Project
问题描述
我目前需要对Web解决方案进行负载测试,该测试需要在首页(欢迎页面)中进行用户身份验证.
当我寻找在FireFox中使用FireBug与登录凭据一起传递的POST登录参数时,
我发现,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.
因此,我已经进行了HTTP REQUEST(访问登录页面),以使用JMETER导航到该页面,该页面可以成功工作.
Therefore i have made a HTTP REQUEST (Visit Login Page) to Navigate to the page using JMETER, which successfully work.
在HTTP REQUEST(访问登录页面)中,我添加了一个正则表达式提取器以提取令牌, 因为必须将令牌和登录信息一起传递.
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
- 默认值:(空白)
- Reference Name : REQUEST_VERIFICATION_TOKEN
- Reg Expression : input name="__RequestVerificationToken" type="hidden" value="([A-Za-z0-9+=/-\ _]+?)"
- Template : $1$
- Match No. : 1
- Default Value : (blank)
我还添加了一个单独的HTTP请求(登录到Web)以及以下参数,用于登录;
And I have added a separate HTTP Request (Login to Web) for signin along with the Parameters as follows;
- 密码: $ {Password}
- TenantName: $ {TenantName}
- 用户名: $ {Username}
- __ RequestVerificationToken: $ {REQUEST_VERIFICATION_TOKEN}
- Password : ${Password}
- TenantName : ${TenantName}
- Username : ${Username}
- __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 =租户&用户名= 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?
(附言:老实说,当您提供宝贵的答复时,请足够假设我是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.
这篇关于JMeter在ASP MVC 5项目中没有对RequestVerificationToken进行识别/未将其分配给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!