troubleshooting Question

.Net Core URL Mapping Restful Web APIs

Avatar of Kyle Abrahams
Kyle AbrahamsFlag for United States of America asked on
.NET ProgrammingC#* ASP.NET Core* asp.net core mvc
12 Comments1 Solution37 ViewsLast Modified:
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)
<server>/API/HelpdeskService/GetTickets/
<server>/API/HelpdeskService/GetTickets?closed=true
<server>/API/HelpdeskService/GetTickets?creator=93
<server>/API/HelpdeskService/GetTickets?creator=93&closed=false

But I'm having issues passing in the parameters.

 app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllers();


                    endpoints.MapControllerRoute(
                    name: "Default",
                    pattern: "{controller}/{action}",
                    defaults: new { controller = "Helpdesk", action = "GetTickets" }
                    );
                });
            }

    [ApiController]
    [Route("")]
    [Route("[controller]")]
    [Authorize]
    public class HelpdeskController : BaseController
    {

        [HttpGet("GetTickets/{Creator:int?}/{closed:bool?}")]        
        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();
        }
   }


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

            return dto.ticket;
        }


How do I wire this up properly?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 12 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros