Share via


Walkthrough: Correlating Dynamic Parameters

In this walkthrough, you create an ASP.NET Web application that includes custom code to create a non-detectable dynamic parameter error. You will learn how to isolate such errors and correct them.

Some Web sites and applications use dynamic parameters in one or more of their Web requests. A dynamic parameter is a parameter whose value is generated every time that a user runs the application. A dynamic parameter can cause your Web performance test playback to fail because the dynamic value will likely be different every time that the test is run. Therefore, you cannot play back recorded values. An example of a dynamic parameter is a session ID. Its value is changed once every 5 to 30 minutes.

The Web performance test recorder and playback engine automatically handle the most common types of dynamic parameters:

  • Dynamic parameter values set in cookie value. The Web performance test engine automatically handles these during playback.

  • Dynamic parameter values set in hidden fields on HTML pages, such as ASP.NET view state. These are automatically handled by the Web performance Test Recorder. The Web Performance Test Recorder adds hidden field extraction rules to the test.

  • Dynamic parameter values set as query string or form post parameters. These are handled through dynamic parameter detection when the test is complete.

However, there are still some forms of dynamic parameters that are not automatically handled. To handle these parameters correctly, you can add extraction rules to dynamic parameters in your Web performance tests. However, before you add an extraction rule, you have to locate where a dynamic parameter is initialized. This walkthrough shows how to locate and correct a mock non-detectable session ID dynamic parameter error.

In this walkthrough, you will complete the following tasks:

  • Create an ASP.NET Web application.

  • Add some ASP.NET pages to the application.

  • Add some controls to the application.

  • Modify the ASP.NET code.

  • Add some C# code behind.

  • Add some Javascript to cause a non-detectable dynamic parameter.

  • Record a new Web performance test on the application and notice a detected ASP.NET dynamic property.

  • Run the Web performance test and notice that it has a non-detected dynamic parameter.

  • Use quick find during playback in the Web Performance Test Results Viewer to isolate the dynamic parameter error.

  • Add an extraction rule to the dynamic parameter.

  • Bind the extraction rule to the dynamic parameter in the Web Performance Test Editor.

  • Run the Web performance test again without errors.

Prerequisites

  • Microsoft Visual Studio 2010 Ultimate.

Creating a Web Application

To create the Web application

  1. In Visual Studio 2010 Ultimate, on the File menu, click New and then click Project.

    The New Project dialog box appears.

  2. Under Installed templates, expand the programming language that you prefer and then click Web.

  3. In the list of Web project types, select ASP.NET Empty Web Application.

  4. In the Name box, type DynamicParameterSample.

  5. In the Location box, specify the folder where you want to create your Web application.

  6. Select Create directory for solution.

  7. Click OK.

  8. On the Project menu, choose Add New Item.

    The Add New Item dialog box appears.

  9. In the list of items, choose Web Form.

  10. In the Name text box, type Querystring.aspx and then click Add.

Adding a HiddenField Control to the Querystring.aspx Page

To add a HiddenField control to the Querystring.aspx page

  1. In Solution Explorer, right-click Querystring.aspx and choose View Designer.

    A blank page is displayed.

  2. If the toolbox is not visible, click View and then click Toolbox.

  3. From the Standard group, drag a HiddenField onto the page.

    A HiddenField control is added to the design surface.

  4. Click the HiddenField on the page, and in the Properties window, in the Misc category, change the value for (ID) to HiddenFieldSessionID.

  5. On the File menu, click Save All.

Adding Code to the Querystring.aspx Page

To add code to the Querystring.aspx page

  1. On the bottom of the Querystring page, click Source.

    The Code Editor is displayed with the ASP.NET code for the Querystring.aspx page.

  2. Add the following highlighted ASP.NET and JavaScript code used to generate the mock session ID dynamic parameters:

    <head runat="server">
    <title>Javascript dynamic property correlation sample</title>
    <script type="text/javascript" language="javascript">
        <!--
            function jScriptQueryString() 
            {
                var Hidden = document.getElementById("HiddenFieldSessionID");
                var sessionId = Hidden.value;
                window.location = 'JScriptQuery.aspx?CustomQueryString=jScriptQueryString___' + sessionId; 
            }
        //-->
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
             <a name="QuerystringHyperlink" href="ASPQuery.aspx?CustomQueryString=ASPQueryString___<%= Session.SessionID %>">Dynamic querystring generated by ASP.net</a>
             <br/>
             <br/>
             <a href="javascript:jScriptQueryString()">Dynamic querystring generated by javascript </a>
        </div>
        <asp:HiddenField ID="HiddenFieldSessionID" runat="server" />
        </form>
    </body>
    </html>
    
  3. Right-click the Querystring page, and select View Code.

    The Code Editor is displayed with the Visual C# code behind for the Querystring.aspx page.

  4. Add the following highlighted code to the Page_Load method:

        public partial class Querystring : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                Session.Add("Key", "Value");
                HiddenFieldSessionID.Value = Session.SessionID;
            }
        }
    
  5. On the File menu, click Save All.

Add ASPQuery.aspx Page, Controls and Code

To add the ASPQuery.aspx page to the Web application

  1. On the Project menu, click Add New Item.

  2. In the Add New Item dialog box, click the Web Form template, and in Name type ASPQuery.aspx, and then click Add.

  3. On the File menu, click Save All.

To add controls to the ASPQuery.aspx page

  1. In Solution Explorer, right-click ASPQuery.aspx and choose View Designer.

    A blank page is displayed.

  2. In the Toolbox, from the Standard group, drag a Label onto the page.

    A Label control is added to the design surface.

  3. Click the Label on the page, and in the Properties window, in the Misc category, change the value for (ID) to IndexLabel.

  4. In the Toolbox, from the Standard group, drag a HyperLink onto the page.

    A HyperLink control is added to the design surface.

  5. Click the HyperLink on the page, and in the Properties window, in the Appearance category, change the vale for Text to Back.

  6. In the Navigation category, click () for the NavigationURL property.

    The Select URL dialog box is displayed.

  7. In the list of pages under Contents of folder, select Querystring.aspx and click OK.

  8. On the File menu, click Save All.

To add code behind to the ASPQuery.aspx page

  1. Right-click the ASPQuery page, and select View Code.

    The Code Editor is displayed with the Visual C# code behind for the ASPQuery.aspx page.

  2. Add the following highlighted code to the Page_Load method:

    protected void Page_Load(object sender, EventArgs e)
            {
                int index;
                string qstring;
                string dateportion;
                string sessionidportion;
    
                qstring = Request.QueryString["CustomQueryString"];
                index = qstring.IndexOf("___");
                dateportion = qstring.Substring(0, index);
                index += 3;
                sessionidportion = qstring.Substring(index, qstring.Length - index);
    
                if (sessionidportion != Session.SessionID)
                {
                    Response.StatusCode = 401;
                    IndexLabel.Text = "Failure!  Invalid querystring parameter found.";
                }
                else
                {
                    IndexLabel.Text += "Success.  Dynamic querystring parameter was found.";
                }
                IndexLabel.Text += "<br>\r\n";
            }
    
  3. On the File menu, click Save All.

Add JScriptQuery.aspx Page, Controls and Code

To add the JScriptQuery.aspx page to the Web application

  1. On the Project menu, click Add New Item.

  2. In the Add New Item dialog box, click the Web Form template, and in Name type JScriptQuery.aspx, and then click Add.

  3. On the File menu, click Save All.

To add controls to the JScriptQuery.aspx page

  1. In Solution Explorer, right-click JScriptQuery.aspx and choose View Designer.

    A blank page is displayed.

  2. In the Toolbox, from the Standard group, drag a Label onto the page.

    A Label control is added to the design surface.

  3. Click the Label on the page, and in the Properties window, in the Misc category, change the value for (ID) to IndexLabel.

  4. In the Toolbox, from the Standard group, drag a HyperLink onto the page.

    A HyperLink control is added to the design surface.

  5. Click the HyperLink on the page, and in the Properties window, in the Appearance category, change the vale for Text to Back.

  6. In the Navigation category, click () for the NavigationURL property.

    The Select URL dialog box is displayed.

  7. In the list of pages under Contents of folder, select Querystring.aspx and click OK.

  8. On the File menu, click Save All.

To add code behind to the JScriptQuery.aspx page

  1. Right-click the JScriptQuery page, and select View Code.

    The Code Editor is displayed with the Visual C# code behind for the JScriptQuery.aspx page.

  2. Add the following highlighted code to the Page_Load method:

    protected void Page_Load(object sender, EventArgs e)
            {
                int index;
                string qstring;
                string dateportion;
                string sessionidportion;
    
                qstring = Request.QueryString["CustomQueryString"];
                index = qstring.IndexOf("___");
                dateportion = qstring.Substring(0, index);
                index += 3;
                sessionidportion = qstring.Substring(index, qstring.Length - index);
    
                if (sessionidportion != Session.SessionID)
                {
                    Response.StatusCode = 401;
                    IndexLabel.Text = "Failure!  Invalid querystring parameter found.";
                }
                else
                {
                    IndexLabel.Text += "Success.  Dynamic querystring parameter was found.";
                }
                IndexLabel.Text += "<br>\r\n";
            }
    
  3. On the File menu, click Save All.

Testing the Web Application Manually

To test the Web application manually

  1. In Solution Explorer, right-click Querystring.aspx and then click Set As Start Page.

  2. Press CTRL+F5 to run the Web application in the browser. You will see the first page.

  3. Click the Dynamic querystring generated by ASP.NET link.

  4. The ASPQuery.aspx page is displayed with the message "Success. Dynamic querystring parameter found."

  5. Click the Back link.

  6. Click the Dynamic querystring generated by javascript link.

  7. The JScriptQuery.aspx page is displayed with the message "Success. Dynamic querystring parameter found.".

  8. Click the Back link.

  9. Copy the address of your Web application to the clipboard or a notepad file. For example, the address might look as follows:

    https://localhost:<PortNumber>/Querystring.aspx.

    When you create a Web performance test later in this walkthrough, you will need the URL.

Creating a Test Project

To create the test project

  1. On the File menu, point to Add and then click New Project.

    The Add New Project dialog box appears.

  2. Under Installed Templates, expand Visual C# and select Test.

  3. In the list of templates, choose Test Project.

  4. In the Name box, type DynamicParameterSampleTest.

  5. Click OK.

    Note

    By default, Visual Studio 2010 Ultimate will add a unit test file. You will not need the unit test file for this walkthrough. Therefore you can delete the file. If you do not delete the file, it will not affect the walkthrough.

Recording a Web Performance Test and Automatically Detect Dynamic Parameter for ASPQuery.aspx Page

To record the Web performance test

  1. On the Test menu, click New Test.

    The Add New Test dialog box appears.

  2. In the Add New Test dialog box, select Web Performance Test, name the test DynamicParameterSampleApp.webtest, and then click OK.

    A new Web performance test file that is named DynamicParameterSampleApp.webtest is added to your project, and the Web Performance Test Recorder opens inside a new instance of Internet Explorer.

    Warning

    For the next procedure to work correctly, you must to follow these steps in the order shown.

  3. In the browser's address bar, type or paste the address of the Web application that you copied in the procedure To test the Web application manually step, and press ENTER.

    Note

    Visual Studio 2010 Ultimate begins to display the Web performance test URLs in the Web Performance Test Recorder as it is recording.

  4. Click the Dynamic querystring generated by ASP.NET link.

    The ASPQuery.aspx page is displayed with the message "Success. Dynamic querystring parameter found."

  5. Click the Back link.

  6. Click the Dynamic querystring generated by javascript link.

  7. The JScriptQuery.aspx page is displayed with the message Success. Dynamic querystring parameter found.

  8. Click the Back link.

  9. To stop recording, click Stop on the Web Performance Test Recorder.

    A dialog box displays the message Detecting dynamic parameters. It also displays a progress bar that shows the status of parameter detection in the HTTP responses that were received.

    Next, the Promote Dynamic Parameters to Web Test Parameters dialog box is displayed.

    Promoting dynamic parameters

    Because the custom code that is added for the dynamic parameter in CustomQueryString in the ASPQuery page in the procedure was automatically detected, it is listed in the dialog box.

    The dynamic parameter for CustomQueryString in the JScriptQuery page was not automatically detected because the custom Javascript code was added to the Querystring.aspx page in the procedure Adding Code to the Querystring.aspx Page.

  10. Click OK to add an extraction rule added to the Querystring.aspx .

    The Web Performance Test Editor is displayed with the first request for Querystring.aspx fully expanded. It shows the extraction rule that was added.

  11. Fully expand the second request in the request tree for ASPQuery.aspx and notice that the CustomQueryString's value has been bound to the extraction rule.

    Extraction rule added for dynamic parameter

  12. Choose File and then choose Save DynamicParameterSampleApp.webtest to save the newly recorded Web performance test.

Play the Web Performance Test to Produce the Non-Detected Dynamic Parameter Error

To play back the Web Performance Test

  1. In the Web Performance Test Editor, click Run on the toolbar to display the Web Performance Test Results Viewer.

  2. Notice that the fourth request failed with an error. The fourth request is for the JScriptQuery.aspx page.

    Non-detected dynamic parameter error

Isolate the Dynamic Parameter Causing the Error

To use quick find in the playback recording

  1. In the Web Performance Test Results Viewer, right-click the fourth request. The fourth request is for the JScriptQuery.aspx page that failed because of the dynamic parameter issue. Select Go to Web Test.

    Go to Web Test

    The Web Performance Test Editor is displayed with the JScriptQuery.aspx request highlighted.

  2. Fully expand the request node and notice that the "wy0zaykqadkoscuvoiqemofm" portion of the CustomQueryString appears to be dynamic: " CustomQueryString=jScriptQueryString___wy0zaykqadkoscuvoiqemofm".

    Web Performance Test Editor request with error

  3. Return to the Web Performance Test Results Viewer and select the JScriptQuery.aspx page that failed.

  4. Click the Request tab.

  5. Verify that the Show raw data check box is cleared.

  6. Scroll down until you find QueryString Parameters under the Name column.

  7. Right-click CustomQueryString and select Quick Find.

    Isolating a dynamic parameter

  8. In the Find dialog box, the parameters value is displayed in Find what.

    In this case, you know from looking at the Web Performance Test Editor, that the JScriptQuery.aspx request's CustomQueryString was assigned a value of: jScriptQueryString___wy0zaykqadkoscuvoiqemofm and that the suspected dynamic portion is "wy0zaykqadkoscuvoiqemofm".

  9. In the Find what drop-down list, remove the suspect portion of the search string. The string should be "CustomQueryString=jScriptQueryString___".

    Find dialog box

  10. Dynamic parameters are assigned their values in one of the requests that precedes the request that has the error. Therefore, select the Search up check box and click Find Next until you see preceding request for Querystring.aspx highlighted in the Request panel. This should occur after you click Find Next three times.

    Isolating dynamic error using find

    As you can see in the illustration, and the Javascript implemented earlier, the query string parameter CustomQueryString is assigned a value of " jScriptQueryString___" and is also concatenated with the returned value from the var sessionId.

            function jScriptQueryString() 
            {
                var Hidden = document.getElementById("HiddenFieldSessionID");
                var sessionId = Hidden.value;
                window.location = 'JScriptQuery.aspx?CustomQueryString=jScriptQueryString___' + sessionId; 
            }
    

    Now you know where the error is occurring, and you also know that you need to extract the value for sessionId. However, the extraction value is only text, so you need to further isolate the error by trying to locate a string where the sessionId's actual value is displayed. By looking at the code, you can see that the var sessionId equals the value returned by HiddenFieldSessionID.

  11. Highlight HiddenFieldSessionID, right-click it, and then select Quick Find.

  12. In the Find dialog box, clear the Search up check box and select Current request.

  13. Click Find Next.

    The first match of HiddenFieldSessionID is highlighted in the following line. You can also see the value that it is assigned:

    <input type="hidden" name="HiddenFieldSessionID" id="HiddenFieldSessionID" value="0rvcxknlabd30xnbrjtuy11u" />
    

    Find HiddenFieldSessionID

    Notice that the value returned is not the same string as in the original Web Performance Test recording. For this playback, the value is "0rvcxknlabd30xnbrjtuy11u" and in the recording, the value is "wy0zaykqadkoscuvoiqemofm". Because the value does not match that of the original recording, the error is generated.

To add an extraction rule from the recorded playback

  1. In the Web Test Results Viewer, click Recorded Result in the toolbar.

    The original recorded results of the Web performance test is displayed in a separate tab titled DynamicParameterSampleApp[Recorded].

  2. If it is not selected already, select the third request. It is the Querystringrequest.aspx that you isolated in the previous step.

  3. Click the Response tab. Scroll down and highlight the original dynamic parameter value of "wy0zaykqadkoscuvoiqemofm" that you isolated in the previous procedure. Right-click it and select Add Extraction Rule.

    Add Extraction Rule

    The Web Performance Test Editor is displayed with the new extraction rule selected in the Querystring.aspx request. The new extraction rule is assigned a value of 'Param0'.

    The Microsoft Visual Studio dialog box is displayed with information that a match was found for the extracted text to bind the parameter to.

    Extraction rule added as param(0)

  4. Click Yes.

    The Find and Replace in Request dialog box is displayed with the extracted text wy0zaykqadkoscuvoiqemofm in the Find what drop-down list and the parameter {{Param0}} in the Replace with drop-down list.

    Find next Param0

  5. Click Find Next.

  6. The QueryString parameter under the JScriptQuery.aspx request CustomQueryString=jScriptQueryString___wy0zaykqadkoscuvoiqemofm is highlighted.

  7. Click Replace.

    Updated query string using Param(0)

  8. The QueryString parameter under the JScriptQuery.aspx request is updated by using the new context parameter: CustomQueryString=jScriptQueryString___{{Param0}}.

  9. Notice the similar structure of in the request tree between the detected dynamic parameter and the non-detected dynamic parameter that you correlated.

See Also

Tasks

How to: Promote Dynamic Parameters to Web Performance Test Parameters

Concepts

Web Performance Test Results Viewer Overview

Other Resources

Resolving Web Performance Test Result Viewer Playback Issues in Web Performance Tests