ViewState 是 ASP.NET 用来存放网页上服务端控件 (server control) 状态的一个隐藏域,如果你查看ASP.NET 网页的source,能看到一个"_VIEWSTATE"的值,如下:
<img src="/images/clear.gif" alt="" height="5" width="1" border="0" /></td><td class="contentColumn">
<table class="contentTable"><tr><td class="contentColumn">
<!-- ContentStart -->
<form name="_ctl1" method="post" action="/articleViewer.aspx?aId=135&pId=" id="_ctl1">
<input type="hidden" name="__VIEWSTATE" value="dDwtMTgzMTYyNTQ3Mzt0PHA8bDxhcnRpY2xlSWQ7dmVyc2lvbklkO3BhZ2VJZDs
+O2w8aTwxMzU+O2k8MT47aTwxPjs+PjtsPGk8MT47aTw1Pjs+O2w8dDw7bDxpPDM+O
z47bDx0PDtsPGk8Mjk+O2k8Mzk+Oz47bDx0PHQ8cDxwPGw8QXV0b1Bvc3RCYWNrO1Z
pc2libGU7PjtsPG88dD47bzxmPjs+Pjs+Ozs+Ozs+O3Q8O2w8aTwwPjtpPDI+Oz47bDx0P
HA8bDxWaXNpYmxlOz47bDxvPHQ+Oz4+Ozs+O3Q8cDxwPGw8VmlzaWJsZTs+O2w8bzx
mPjs+Pjs+Ozs+Oz4+Oz4+Oz4+O3Q8O2w8aTwwPjs+O2w8dDxwPGw8XyFJdGVtQ291b
nQ7PjtsPGk8MT47Pj47bDxpPDA+Oz47bDx0PDtsPGk8MD47aTwxPjs+O2w8dDxAPFdlYiB
Ib3N0aW5nOz47Oz47dDxwPGw8XyFJdGVtQ291bnQ7PjtsPGk8ND47Pj47bDxpPDA+O2k
8MT47aTwyPjtpPDM+Oz47bDx0PDtsPGk8MD47PjtsPHQ8QDxodHRwOi8vd3d3Lmhvc3Rz
ZWFyY2guY29tL2FzcF93ZWJfaG9zdGluZy5hc3A7QVNQLm5ldCB3ZWIgaG9zdGluZzs+Oz
s+Oz4+O3Q8O2w8aTwwPjs+O2w8dDxAPGh0dHA6Ly93d3cuZGlzY291bnRhc3AubmV0L
3NwX2FzcG5ldDIuYXNweDtBU1AuTkVUIDIuMCBIb3N0aW5nOz47Oz47Pj47dDw7bDxpP
DA+Oz47bDx0PEA8aHR0cDovL3d3dy5vcmNzd2ViLmNvbS9yZGlyZWN0cy90ZXh0bGlua1
9hc3BhbGxpYW5jZS5hc3B4OyMxIFNlcnZpY2UgJiBTdXBwb3J0Oz47Oz47Pj47dDw7bDxp
PDA+Oz47bDx0PEA8aHR0cDovL3d3dy5hY2N1d2ViaG9zdGluZy5jb207QXNwLk5ldCBXZ
WIgSG9zdGluZzs+Ozs+Oz4+Oz4+Oz4+Oz4+Oz4+Oz4+Oz4pmBb/T8ok8hRIEP85/r6TO
FSEzA==" />
VIEWSTATE的值在每次出现页面时都会不同,因此在用LoadRunner针对这种类型的应用录制脚本时,就需要进行关联 (Correlation) 操作。一般来说,使用web_reg_save_param函数就可以进行关联,例如:
web_reg_save_param("MyViewState","LB=\"__VIEWSTATE\" value=\"","RB=\"",LAST);
特别要注意的有两点:
1、LoadRunner在某些情况下会对部分VIEWSTATE进行关联,但LR的自动关联在大部分情况下都不那么可靠,因此,建议自行检查一遍自动关联后的脚本,或者直接用手工关联方式处理脚本;
2、如果 ASP.NET 页面上的控件太多,VIEWSTAT的值 (字符串) 会变得很长,而缺省情况下,一个web参数的大小是256 bytes,因此,在 web_reg_save_param 函数之前需要用 web_set_max_html_param_len 函数将参数长度放大。