Ondra Starenko
Ondra Starenko

Reputation: 596

url as parameters? in ASP.NET CORE

Is there a way to read url as parameters?

for example url could be:

downloadSomething.com/data/json/something

And the method:

[HttpGet]
public async Task<Data> Data(string type, string otherParameter)
{
...

I know it's not a good practice.. I just want to know if is it possible.

Thx for help :)

Upvotes: 0

Views: 57

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239440

I'm not sure exactly what you're asking here. The way routing works by default would allow this particular example.

[HttpGet("data/{type}/{otherParameter}")]

If you're talking about actually taking part of the path as a param, you can use the catch-all param, but it must be last param in the route (as it will obviously swallow everything).

[HttpGet("data/{**stuff}")]

That would then set the param stuff with the full path: json/something.

Upvotes: 2

Related Questions