0

After publishing Web API to IIS, which is a child of an AngularJs IIS site, I can reach 'https://localhost/api' and see all endpoints; but when I try to reach some specific endpoint with a GET request, I get an error

Server Error in '/' Application

public class WebApiApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        GlobalConfiguration.Configure(WebApiConfig.Register);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }
}

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.SuppressDefaultHostAuthentication();
        config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    }
}

[RoutePrefix("api/branches")]
public class BranchesController : ApiBaseController
{
    [HttpGet]
    [Route("getBranches")]
    public async Task<JsonResult<List<BranchDto>>> GetActiveBranches()
    {
        var branches = new List<BranchDto>();

        var models = await WarehouseUnitOfWork.BranchRepository.GetActiveBranches();
        if (models != null && models.Count > 0)
        {
            branches.AddRange(AutoMapper.Mapper.Map<List<Branch>, List<BranchDto>>(models));
        }

        return Json(branches, new JsonSerializerSettings
        {
            ContractResolver = new WarehouseCustomContractResolver()
        });
    }
}

Any ideas how to solve this?

8
  • Did you try http://localhost/api instead of https://localhost/api? Commented Oct 6, 2019 at 9:44
  • Yes I've already tried. What else can I do? Commented Oct 6, 2019 at 11:59
  • Can you post your API code? Commented Oct 6, 2019 at 13:49
  • @VoiceOfTheRain Do you want to see a specific controller? Commented Oct 6, 2019 at 14:10
  • Post your web api routing config along with one of your API controllers Commented Oct 6, 2019 at 14:15

1 Answer 1

1

The solution for my case was to deploy the Frontend into the main IIS site, and inside it create an application called v1 for the Backend. Then within my angularJS I defined the Production app to make the http requests to /v1/api instead of /api.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.