Retrieving Values ​​from Any URL

I have this url: http: // localhost: 49500 / Learning / Chapitre.aspx? Id = 2

How can I get only the value idin this URL?

+3
source share
4 answers

You can access all query lines through an array Request.QueryString():

Request.QueryString("id") will provide you 2

+4
source

Despite my own comment that was answered, here is the code.

Dim idval As String = System.Web.HttpUtility.ParseQueryString("http://localhost:49500/Learning/Chapitre.aspx?id=2")("id")
+2
source

System.Uri URL- > t21 > , .

, String.Split '&' . do String.Split '=' char. - , - ( ). , , , , .

: , VB 1999 ...: -)

. , Url, , - URL . Request.QueryString("id") .

    Dim url As Uri = New Uri("http://localhost:49500/Learning/Chapitre.aspx?id=2")
    Dim query As String = url.Query.Trim("?")
    Dim parameters() As String = query.Split("&")
    Dim tokens() As String
    Dim value As String = ""
    For index As Integer = 0 To parameters.Length - 1
        tokens = parameters(index).Split("=")
        If tokens(0).ToLower = "id" Then
            If tokens.Length = 2 Then
                value = tokens(1)
            End If
            Exit For
        End If
    Next
    ' At this point value contains the parameter value or
    ' is empty if the parameter has no value or if the parameter is not present
0

vb URL: http://localhost:49500/Learning/Chapitre.aspx?id=2

Dim valueId = Request("id")

to check the code:

response.Write(valueId)

Id value is 2

0
source

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


All Articles