0

我有一个应用程序可以抓取网站以获取唯一链接 url(即 hrefs),然后将这些 url 保存到数据库中。我将确保网站中的每个页面都有 url。下面是获取保存到数据库的字符串的代码。

'url is the url obtained from the link's href
Dim uriReturn As Uri = New Uri(url, UriKind.RelativeOrAbsolute)

'Make it absolute if it's relative
If Not uriReturn.IsAbsoluteUri Then
     Dim baseUri As New Uri(BaseUrl)
     uriReturn = New Uri(baseUri, uriReturn)
End If

Return LCase(uriReturn.ToString)

在应用程序的另一部分,我有部分使用当前页面的 url 查询数据库。下面是获取当前页面 url 的代码。

Dim CurrentURL As String = lcase(HttpContext.Current.Request.Url.AbsoluteUri

我的问题是我可以确定我会使用当前页面 url 在数据库中找到匹配项吗?那就是从href得到的字符串和从当前页面返回的字符串即使指向同一个页面也会有区别吗?有没有办法转换网址以确保它们始终匹配?

4

1 回答 1

0

Since BaseURl is not defined, can't tell if you got it correct. But BaseUrl should be = Request.Url.

And your

Dim CurrentURL As String = lcase(HttpContext.Current.Request.Url.AbsoluteUri

Since you are doing store/retrieve, I suggests you standardize your methods. In store section, you use uriReturn.ToString(), so in the retrieve section, you should also use ToString() instead of AbsoluteUri.

于 2013-03-06T03:12:00.120 回答