Vladyslav Hrehul
Vladyslav Hrehul

Reputation: 73

Routing issue with redirect

Is it possible to create this kind of route: "param1 / param2 / *"

Pseudocode:
 routes.MapRoute(
            name: "Default",
            url: "AppController/Index/*",
            defaults: new { controller = "AppController", action = "Index" }
        );

Example: AppController / Index / test / qwe / 123 -> expect it to be redirected to AppController / Index

And also could this be solved in RouteConfig or should it be some rule in web.config? Or other solution are welcome too :)

Upvotes: 0

Views: 54

Answers (2)

Vladyslav Hrehul
Vladyslav Hrehul

Reputation: 73

url: "AppController/Index/{.*}",

{.*} Simple regex fixed my problem.

Upvotes: 1

Serhatcck
Serhatcck

Reputation: 21

You can do this in methods

...
[HttpGet("{id}")]
public void test(string id)
{
    return Ok(id);
}

uri: localhost:{port}/api/test/{id}

Upvotes: 0

Related Questions