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

2
  • public ActionResult GetAllStudents([FromQuery]string command, [FromQuery]string arguments, [FromQuery]string lastarg) Commented Oct 26, 2021 at 14:47
  • Thanks DavidG for the help. Commented Oct 26, 2021 at 16:19

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.