/// <summary> /// 目标Url是否合法 /// </summary> /// <param name="destUrl"></param> /// <param name="urlCheckParts">需要检查的url中的部分</param> /// <returns></returns> public bool UrlIsValid(Uri destUrl, AccessTicketUrlCheckParts urlCheckParts) { bool result = true; if (this.DestinationUrl.IsNotEmpty()) { Uri uri1 = new Uri(this.DestinationUrl, UriKind.RelativeOrAbsolute); if ((urlCheckParts & AccessTicketUrlCheckParts.SchemeHostAndPort) != AccessTicketUrlCheckParts.None) result = uri1.CompareSchemeAndHost(destUrl); if (result && (urlCheckParts & AccessTicketUrlCheckParts.PathAndParameters) != AccessTicketUrlCheckParts.None) result = uri1.ComparePathAndParameters(destUrl, AccessTicket.AccessTicketParamName); } return result; }
public void NormalPathWithIgnoreParametersEqualTest() { Uri uri1 = new Uri("http://www.baidu.com/test?name=S1&gender=male", UriKind.RelativeOrAbsolute); Uri uri2 = new Uri("http://www.baidu.com/test?Name=S1", UriKind.RelativeOrAbsolute); Assert.IsTrue(uri1.ComparePathAndParameters(uri2, "Gender")); }
public void OneIsRelativePathNotEqualTest() { Uri uri1 = new Uri("http://www.baidu.com/test", UriKind.RelativeOrAbsolute); Uri uri2 = new Uri("/test1", UriKind.RelativeOrAbsolute); Assert.IsFalse(uri1.ComparePathAndParameters(uri2)); }
public void OneIsRelativePathAndAbsUriPathIsSlashEqualTest() { Uri uri1 = new Uri("http://www.baidu.com/", UriKind.RelativeOrAbsolute); Uri uri2 = new Uri("/", UriKind.RelativeOrAbsolute); Assert.IsTrue(uri1.ComparePathAndParameters(uri2)); }
public void RelativePathEqualTest() { Uri uri1 = new Uri("/test", UriKind.RelativeOrAbsolute); Uri uri2 = new Uri("/test", UriKind.RelativeOrAbsolute); Assert.IsTrue(uri1.ComparePathAndParameters(uri2)); }
public void NormalPathEqualTest() { Uri uri1 = new Uri("http://www.baidu.com/test", UriKind.RelativeOrAbsolute); Uri uri2 = new Uri("http://www.baidu.com/test", UriKind.RelativeOrAbsolute); Assert.IsTrue(uri1.ComparePathAndParameters(uri2)); }