locked
asp.net core web api hosting RRS feed

  • Question

  • User1838940990 posted

    Hi all,

    I am very new to asp.net webapi.

    developed a webapi  (core 3.0), need to host it on local machine in our compnay network.

    I published to local folder and copied to folder in new machined where we need to host and pointed the hysical path as "C:\SourceCode\PublishApi" 

    its as widnows 10 Pro and have  installed the ASP.NET Core 3.0 Runtime (v3.0.3) after setting up the iis.

    I configure the host file to   this (127.0.0.1 internalapi  ) so that if I put internalapi/[myapiname]/controller . it should work, but its not working 

    if try browsing the website , getting the below error in the browser.

    Hmmm...can’t reach this page
    Try this
    Make sure you’ve got the right web

    can anybody help me on this.

    Monday, February 24, 2020 8:24 AM

All replies

  • User1120430333 posted

    You followed what is in the link, right?

    https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-3.1&tabs=visual-studio

    Then it should be a simple matter of taking the URL example,  copying it to bowser address line, change localhost the IP of the machine hosting the service, a possible port number and the name of the controller for an action method in the controller. 

    try to get a response from http://localhost:8081/weatherforecast in the browser  on the machine that is  hosting the WebAPI, which in the test controller created by the WebAPI template for a WebAPI project by Visual Stuido.

      using (var client = new HttpClient())
                {
                    var uri = new Uri("http://localhost:8081/payroll/GetAll");
    
                    var response = client.GetAsync(uri).Result;
    
                    if (!response.IsSuccessStatusCode)
                        throw new Exception(response.ToString());
    
                    var responseContent = response.Content;
                    var responseString = responseContent.ReadAsStringAsync().Result;
    
                    dynamic payrolls = JArray.Parse(responseString) as JArray;
    
                    foreach (var obj in payrolls)
                    {
                        DtoPayroll dto = obj.ToObject<DtoPayroll>();
    
                        dtopayrolls.Add(dto);
                    }
                }

    Monday, February 24, 2020 2:55 PM
  • User-474980206 posted

    I configure the host file to   this (127.0.0.1 internalapi  ) so that if I put internalapi/[myapiname]/controller . it should work, but its not working 

    which machine did you do this on? if the new server, then this only works for a browser running on that server. if done on your local box, it points to your local box, not the server.

     

    Monday, February 24, 2020 3:25 PM