Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag for United States of America

asked on 

.Net Core URL Mapping Restful Web APIs

Hi All,

I have .Net Core 3.1 Restful APIs that I'm trying to publish to IIS.  I've been messing with the routes and now broke something.

What I would like is to have the Controller for the service respond to whatever the application is.

I have a website in IIS.  I created an application called API.
Underneath API I'm trying to add my services as more applications.

So you can have something like <server>/API/HelpdeskService

Please note HelpdeskService is the Application name in IIS and NOT the controller.

Within the actual HelpdeskController I have a gets:

One for getTickets with 2 optional parameters, one for the creator and one for closed.  This should map to:
<server>/API/HelpdeskService    (By Default)

But I'm having issues passing in the parameters.

 app.UseEndpoints(endpoints =>

                    name: "Default",
                    pattern: "{controller}/{action}",
                    defaults: new { controller = "Helpdesk", action = "GetTickets" }

Open in new window

    public class HelpdeskController : BaseController

        public async Task<ActionResult<IEnumerable<TicketListDto>>> GetTickets(int? Creator = null, bool? closed = null)
           //closed parameter is null when hitting <server>/?closed=false and <server>/Helpdesk/GetTickets?closed=false
            var dto = await Mediator.Send(new GetTicketsQuery() { user= _currentUserService.user, CreatorId = Creator, Closed = closed });

            return dto.Tickets.ToList();

        public async Task<ActionResult<TicketDetailDto>> GetTicketByID(int ticketID)
            var dto = await Mediator.Send(new GetTicketByIdQuery() { user = _currentUserService.user, TicketID = ticketID });

            return dto.ticket;

Open in new window

How do I wire this up properly?
.NET Programming* asp.net core mvcC#* ASP.NET Core

Avatar of undefined
Last Comment
Kyle Abrahams, PMP

8/22/2022 - Mon