우리는 쿠키를 쿼리 문자열로 이동했습니다.
그 전에는 URL의 세션 구성 요소를 무시하는 대소 문자를 구분하지 않는 URL 유효성 검사 이벤트 처리기를 작성했습니다. 아래의 사례는 대소 문자 구분 만 제거합니다.
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;
}
에 의해 불려
는
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;
}
}
}
}
}
지금은 오직 할 필요가있는 경우에게 문자를 구분 전화를 얻기 위해 웹 테스트에
//add case insensitive url validation for all requests
urlValidationRuleEventHandler = common.AddUrlValidationEventHandler(this.Context, this);
를 추가합니다. 이 코드는 정말 요청을 확인하는 것은 나에게 요청 일반적인 통계를 산출 할 수있는 방법을 이해하지 내 부끄러움을 다음 innappropriate 라인
string fred = "There is a problem";
출처
2010-03-07 23:23:22
Nat
포함되어 있음을 유의 . 한번 더 설명해 주시면 감사하겠습니다. 자, 결국 여기에 내 이야기가 있습니다. 저는 트랜잭션에 요청을 넣고 그 트랜잭션만으로 통계를 얻을 수 있다는 것을 알았습니다. 이것은 코딩을 전혀 요구하지 않으며 대부분의 유스 케이스를 지원할만큼 유연한 것처럼 보입니다. –
죄송합니다, 그건 나쁘다. 유효성 검사기를 사용하여 URL에서 세션을 추출하면 모든 URL이 올바르게 비교됩니다. – Nat
가장 좋은 방법은 세션을 쿼리 문자열로 이동하여 사용자 정의 유효성 검사기를 제거하는 것입니다. – Nat