Webtest with session id in url

We have an ASP.Net site that redirects you to a URL that shows the session ID. eg:

http: // localhost / (S (f3rjcw45q4cqarboeme53lbx)) /main.aspx

This identifier is unique with every request.

Can I test this site using the standard website visual studio 2008/2010? How can I provide this data?

I need to call several different pages using the same id.

+3
source share
1 answer

Yes, it is relatively easy to do this. However, you need to create a coded website.

, url, . , (request3) , .

WebTestRequest request3 = new WebTestRequest((this.Context["WebServer1"].ToString() + "/ICS/Login/English/Login.aspx"));
//more request setup code removed for clarity
yield return request3;
string responseUrl = Context.LastResponse.ResponseUri.AbsoluteUri;
string cookieUrl = GetUrlCookie(responseUrl, this.Context["WebServer1"].ToString(),"/main.aspx"); 
request3 = null;

GetUrlCookie :

public static string GetUrlCookie(string fullUrl, string webServerUrl, string afterUrlPArt)
    {
        string result = fullUrl.Substring(webServerUrl.Length);
        result = result.Substring(0, result.Length - afterUrlPArt.Length);
        return result;
    }

cookie , URL- / .

WebTestRequest request4 = new WebTestRequest((this.Context["WebServer1"].ToString() + cookieUrl + "/mySecureForm.aspx"));

, , - , , :)

, , , .

, URL- , urlValidationEventHandler. validationruleeventhandler :

        ValidateResponseUrl validationRule1 = new ValidateResponseUrl();
        urlValidationRuleEventHandler = new EventHandler<ValidationEventArgs>(validationRule1.Validate);

, :

this.ValidateResponse -= urlValidationRuleEventHandler ;
this.ValidateResponse += urlValidationRuleEventHandler ;

, ( Visual Studio .

class QueryLessCaseInsensitiveValidateResponseUrl : ValidateResponseUrl
{
    public override void Validate(object sender, ValidationEventArgs e)
    {
        Uri uri;
        string uriString = string.IsNullOrEmpty(e.Request.ExpectedResponseUrl) ? e.Request.Url : e.Request.ExpectedResponseUrl;
        if (!Uri.TryCreate(e.Request.Url, UriKind.Absolute, out uri))
        {
            e.Message = "The request URL could not be parsed";
            e.IsValid = false;
        }
        else
        {
            Uri uri2;
            string leftPart = uri.GetLeftPart(UriPartial.Path);
            if (!Uri.TryCreate(uriString, UriKind.Absolute, out uri2))
            {
                e.Message = "The request URL could not be parsed";
                e.IsValid = false;
            }
            else
            {
                uriString = uri2.GetLeftPart(UriPartial.Path);
                ////this removes the query string
                //uriString.Substring(0, uriString.Length - uri2.Query.Length);
                Uri uritemp = new Uri(uriString);
                if (uritemp.Query.Length > 0)
                {
                    string fred = "There is a problem";
                }
                //changed to ignore case
                if (string.Equals(leftPart, uriString, StringComparison.OrdinalIgnoreCase))
                {
                    e.IsValid = true;
                }
                else
                {
                    e.Message = string.Format("The value of the ExpectedResponseUrl property '{0}' does not equal the actual response URL '{1}'. QueryString parameters were ignored.", new object[] { uriString, leftPart });
                    e.IsValid = false;
                }
            }
        }
    }
}
+4

Source: https://habr.com/ru/post/1724003/


All Articles