JMeter测试ASP.Net应用:多__VIEWSTATE字段成因及是否需全部发送咨询
Why Do You See Multiple __VIEWSTATE* Fields?
ASP.NET splits the ViewState into multiple chunks when its size exceeds a configured threshold, controlled by the maxPageStateFieldLength setting in your application's web.config.
- By default, this value is
-1(meaning no splitting), but if your app has a large amount of ViewState—from complex server controls, heavy data binding, or lots of page state data—the framework will split it into smaller segments. This avoids hitting browser or server limits on the size of a single request parameter. - The
__VIEWSTATEFIELDCOUNTparameter acts as a marker for the ASP.NET runtime, telling it exactly how many split ViewState chunks to expect so it can reassemble them correctly on the server side.
Do You Need to Send All These Parameters in JMeter?
Absolutely yes.
The ASP.NET backend requires every single __VIEWSTATE1, __VIEWSTATE2, ..., __VIEWSTATE33 parameter plus __VIEWSTATEFIELDCOUNT to reconstruct the full ViewState. Missing even one of these will cause the server to fail processing your request, which is almost certainly why you're seeing an error page in your second step.
How to Handle This in JMeter
Hardcoding these values will break immediately (ViewState changes with every request and is session-specific), so use dynamic extraction:
- Regular Expression Extractor: Create a regex like
name="(__VIEWSTATE\d+)" value="([^"]+)"to capture each split ViewState field's name and value, plus another extractor for__VIEWSTATEFIELDCOUNT. - CSS/JQuery Extractor: Use a selector like
input[name^='__VIEWSTATE']to target all ViewState-related inputs, then extract both their names and values. - Auto-Correlation During Recording: If you recorded your test plan, enable auto-correlation in the HTTP(S) Test Script Recorder—it should automatically detect and add extractors for these ViewState parameters.
Always make sure you extract the latest ViewState values from the immediate previous response before sending your next request.
内容的提问来源于stack exchange,提问作者thawsoftware

