dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.35k stars 9.99k forks source link

QueryHelpers #20671

Closed imclint21 closed 3 years ago

imclint21 commented 4 years ago

Hi,

I use ParseQuery to get queries from the query string.

var query = QueryHelpers.ParseQuery("/ticket-details/?ticket=8DE473F6-3DC6-4002-BE0F-EC4CE20445D81");

And I get this, I think it's a problem if this library does not parse correctly

{
  "/ticket-details/?ticket": [
    "8DE473F6-3DC6-4002-BE0F-EC4CE20445D81"
  ]
}

Best regards

davidfowl commented 4 years ago

QueryHelpers.ParseQuery taks a query string, not a path an a querystring:

var query = QueryHelpers.ParseQuery("?ticket=8DE473F6-3DC6-4002-BE0F-EC4CE20445D81");

See the doc comment (as small as it is):

https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.webutilities.queryhelpers.parsequery?view=aspnetcore-3.1

The raw query string value, with or without the leading '?'.

imclint21 commented 4 years ago

Oh yeah my bad, however maybe it could be great to parse the complete URI if it's passed?

davidfowl commented 4 years ago

That would be a different API, you can use URI to parse the url then get the query part and pass it in here

claudiogodoy99 commented 4 years ago

you can use [FromQuery] in your endpoint controller, like this:

[HttpGet()]
public IActionResult Get([FromQuery(Name = "ticket")] string ticket)

https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-3.1

ghost commented 3 years ago

Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!