У меня есть этот контроллер:
Public Class UsersController
Inherits ApiController
Public reportsjsonfilepath = System.AppDomain.CurrentDomain.BaseDirectory & "\reports.json"
<HttpGet>
<Route("")>
Public Function Index() As HttpResponseMessage
Log.Information("Main index requested at {0}", DateTime.Now)
Dim response As StringBuilder = New StringBuilder
response.Append("Index requested at: " & DateTime.Now)
response.Append("<br>")
response.Append("Hello, this is a test WebApi server!")
Dim raspuns = String.Join("/n", response.ToString)
Dim raspunsindex = Request.CreateResponse(Of String)(HttpStatusCode.OK, raspuns)
raspunsindex.Content.Headers.ContentType = New MediaTypeHeaderValue("text/html")
Return raspunsindex
End Function
<HttpGet>
<Route("users")>
Public Function Users() As HttpResponseMessage
Log.Information("Users index requested at {0}", DateTime.Now)
Dim response As StringBuilder = New StringBuilder()
Dim dictionarusers As IDictionary(Of String, String) = GetUsersList()
Dim i As Integer = 0
For Each entry As KeyValuePair(Of String, String) In dictionarusers
i = i + 1
response.Append(i)
response.Append(" - ")
response.Append(entry.Value)
response.Append("<br>")
Next
Dim raspuns = Request.CreateResponse(Of String)(HttpStatusCode.OK, response.ToString)
raspuns.Content.Headers.ContentType = New MediaTypeHeaderValue("text/html")
Return raspuns
End Function
<HttpGet>
Public Function GetQlikLink(username As String, reportId As Integer) As HttpResponseMessage
QlikLink.GetLink(username, reportId)
End Function
End Class
Маршруты настроены так:
Public Module RoutesConfig
<Extension()>
Sub MapDefinedRoutes(ByVal config As HttpConfiguration)
config.Routes.MapHttpRoute(name:="Relevance", routeTemplate:="api/{controller}", defaults:=New With {
.id = RouteParameter.[Optional]
})
config.Routes.MapHttpRoute("QlikLink", "api/{controller}/{action}/{id}", New With {
.id = RouteParameter.[Optional]
})
End Sub
End Module
Теперь, когда я иду http://localhost:9000/relevance
, индекс начинает работать нормально.То же самое для http://localhost:9000/relevance/users
.Но как настроить действие и маршрут, чтобы получить что-то, получая параметры из запроса?Как отправляются параметры:? Username = somestring &? Id = 2?Я говорю о функции GetQlikLink
, последней из Controller
.
Любая подсказка будет оценена по достоинству!Большое спасибо!