我正在使用 Visual Studio 负载测试工具对网页进行负载测试,但显示结果时出现问题。问题是无cookie会话。每次新用户访问页面时,页面 URLL 都会发生变化,我无法计算平均页面响应时间。可以做些什么呢?
问问题
418 次
1 回答
0
我们将 cookie 移至查询字符串。
在此之前,我编写了一个不区分大小写的 url 验证事件处理程序,它忽略了 Url 的会话组件。下面的一个仅删除区分大小写。
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;
}
}
}
}
}
调用者
public EventHandler<ValidationEventArgs> AddUrlValidationEventHandler(WebTestContext context, WebTest webTest)
{
EventHandler<ValidationEventArgs> urlValidationRuleEventHandler = null;
// Initialize validation rules that apply to all requests in the WebTest
if ((context.ValidationLevel >= Microsoft.VisualStudio.TestTools.WebTesting.ValidationLevel.Low))
{
QueryLessCaseInsensitiveValidateResponseUrl validationRule1 = new QueryLessCaseInsensitiveValidateResponseUrl();
urlValidationRuleEventHandler = new EventHandler<ValidationEventArgs>(validationRule1.Validate);
webTest.ValidateResponse += urlValidationRuleEventHandler;
}
return urlValidationRuleEventHandler;
}
现在我需要做的就是添加
//add case insensitive url validation for all requests
urlValidationRuleEventHandler = common.AddUrlValidationEventHandler(this.Context, this);
进入网络测试以获得不区分大小写的调用。请注意,此代码包含以下不适当的行
string fred = "There is a problem";
于 2010-03-07T23:23:22.790 回答