How to get localhost to work when doing .NET Web API tutorial

Mac Perkins 0 Reputation points
2024-11-08T00:21:04.6066667+00:00

I am working on the following tutorial:
https://learn.microsoft.com/en-us/training/modules/build-web-api-aspnet-core/3-exercise-create-web-api

I am working on the first part, downloading the tutorial app and starting it using dotnet run. When I run it, I get the following error:

warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]

  Failed to determine the https port for redirect.  

I have tried changing the appsettings.json file so that it only accepts the http localhost I am using, which loads something, but it gives me this:

Bad Request - Invalid Hostname


HTTP Error 400. The request hostname is invalid.

What do I need to change to make this work?

Community Center Not monitored
{count} votes

1 answer

Sort by: Most helpful
  1. Pradeep M 9,765 Reputation points Microsoft External Staff Volunteer Moderator
    2024-11-08T04:27:14.8033333+00:00

    Hi Mac Perkins,

    Thank you for reaching out to Microsoft Q & A forum.  

    The 404 error you encountered happens because the base URL only connects to the server itself but doesn’t point to the specific endpoint needed to display the API data. 

    To access your API’s JSON output, please follow these steps: 

    1.Run the app using dotnet run. 

    2.Then, in your web browser, enter the full URL, like this: 

    http://localhost:5290/weatherforecast 

    (Note: Be sure to replace 5290 with the actual port number you see in the terminal if it’s different.) 

    This should bring up the expected JSON response from your API. 

    Please feel free to contact us if you have any additional questions.    

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community

    2 people found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.