Options

ANTSLOAD 16 - Viewstate errors in ANTS Load tests

Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
edited June 16, 2005 6:12AM in Knowledge Base
  • Date: 16 June 2005
  • Versions: 1.5, 1.6

When running a load test after recording a script against an ASP .NET web application, viewstate error messages may appear in the report under summary information by metric: Test Errors. These will appear under the Internal Server Error category.

There are a number of possible reasons for this happening, and the information for troubleshooting the problem follows.

1. ASPX pages may be out of order.
In order to maintain consistent viewstate, a web form must post back the viewstate from the same page that was requested initially by the web client. This means that a WebClient.Get(page) must immediately precede a WebClient.Post(same page). The script recorder in ANTS Load records the actions in order, so there is a potential to get a different page in-between the GET and POST operations to the same web form page.

ANTS Load automatically gets the ViewState from the content of an ASPX page and stores it in WebClient.ViewState. This is then returned to the server on the post operation by adding a WebClient.HttpRequest.AddPostData("__VIEWSTATE", WebClient.ViewState) to the post request.

2. Cookies can be missing or invalid
ANTS Load stores cookies for each virtual client in a cookie store. This is necessary to run many virtual web clients on one machine and still maintain a separate session with the web server for each of them. This is an automatic process as well; ANTS Load will store the Set-Cookie header if one is present in the web response and return that cookie automatically by setting the Cookie header in the following request. If the cookie is not present, this will also result in an invalid viewstate error.

To test this condition, insert Me.LogToFile(WebClient.HttpRequest.Headers.ToString()) and examine AntsTraceLog.txt to make sure that a header called Cookie is being sent to the server with the requests.

If the cookie has net been set, investigate the following possibilities:
  • The web forms login has failed
  • ANTS Load is not working properly (if the login is successful but you find that it is not storing the cookie), contact support at red-gate.com for the latest patch to the software

3. Redirection issues
If the result of a login is a redirection (301 redirect or 302 moved permanently), this can also cause problems since ANTS Load's webclient does not automatically follow redirections. If a login.aspx page redirects to a landing page, then a post to the landing page follows, inconsistent viewstate can result. You can log the WebClient.HttpResponse.Status to the trace log and see if there is a 301 or 302 code returned. Afterwards, you can script a GET to WebClient.HttpResponse.Location. Note that Location may return a relative URL. If so then prepend the URL for the web server to the front of it.
Sign In or Register to comment.