0

I have an application in angular that call a WebApi in AspNet 5 C#. The url is

https://localhost:44390/api/student/GetAllStudents?command=GetDirContents&arguments=%7B%22pathInfo%22%3A%5B%5D%7D&_=1635258865362

I need in the WebApi to read command , arguments and the last uri params.

I have this code in my ApiController

[Route("api/[controller]")]
[ApiController]
public class StudentController : ControllerBase
{
    private readonly IHttpContextAccessor _httpContextAccessor;

    public StudentController(IHttpContextAccessor httpContextAccessor)
    {
        _httpContextAccessor = httpContextAccessor;
    }


    [HttpGet("GetAllStudents", Name = "[controller]_GetAllStudents")]
    public ActionResult GetAllStudents()
    {
        var routeData = _httpContextAccessor.HttpContext.GetRouteData();
        var command = routeData.Values["command"];
        var arguments = routeData.Values["arguments"];
        var lastarg = routeData.Values["_"];

        ....
        return Ok(); // Testing

    }
}

This is not working it´s always null.

Howto solve this. Thanks

jolynice
  • 514
  • 1
  • 8
  • 25

0 Answers0