Reputation: 823
I've got an API end-point in a .NET Core 3.1 project that is working just fine in localhost, but the moment I publish the app to folder to host by IIS, and I try to access the end-point once live, I get the following error in Chrome:
This page isn’t working
services.apiapptest.com is currently unable to handle this request.
HTTP ERROR 500
I've tried surrounding the controller in a try/catch in hopes to return the exception to screen, but no dice. I still get the plain generic white screen error above. How can I see the details of this exception?
The following is my controller code (if it helps):
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using ApiEmployee.Data;
using ApiEmployee.Models;
namespace ApiEmployee.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class EmployeesController : ControllerBase
{
private ApplicationDbContext _context;
public EmployeesController(ApplicationDbContext context)
{
_context = context;
}
[HttpGet]
public async Task<ActionResult<List<Employee>>> List()
{
return await _context.Employee.ToListAsync();
}
}
}
For some reason the following code works just fine in localhost/production:
List<object> data = new List<object>
{
new
{
EmployeeId = 1,
FirstName = "Bob",
LastName = "Smith",
Email = "[email protected]",
Phone = "",
PhoneExtension = "",
Title = "Party King",
Department = "Party",
PhotoUrl = ""
}
};
return Ok(await Task.FromResult(data));
I'm pretty new to .NET Core so pardon my ignorance.
Upvotes: 0
Views: 1586
Reputation: 1985
Since you have already added try-catch in controller actions and everything is working locally, I would say you are getting 500 error even before reaching controller action which means during request initialization (like constructor or even before that). Since constructor of your controller has database context injection, please verify whether IIS app pool identity has permission to access your database account or not. After this, if you are still getting error, then you can debug further by enabling remote debugging and having breakpoint anywhere either in controller constructor or action of your code.
Upvotes: 1
Reputation: 354
HTTP 500 see more refers to your api url is not reachable for some internal server error like Firewall blocking or wrong url input. Check your URL input after publish.Your route is refers to
services.apiapptest.com/api/{controllername}/{action}
you couldn't get any exception until your request reaches into controller's action. In this scenario you could inspect browser console or network that your requested url is correct or not.
Upvotes: 0