.net core 2.1 VS 2017 basic web api throwing "this site can't be reached"

1,241

The 404 error indicates that there's no such an Endpoint in your web api project.

From your image1, the launchUrl is not set, so when you start your project it will show the url https://localhost:5001/ which results in 404 since you do not have such an endpoint.To make it work, add below api controller:

[Route("/")]
[ApiController]
public class ValuesController : ControllerBase
{
    // GET
    [HttpGet]
    public ActionResult<string> Get()
    {
        return "value";
    }
}

Then it should work:

enter image description here

By default, the web api template would have a default ValuesController(create one if you do not have):

[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
    // GET api/values
    [HttpGet]
    public ActionResult<string> Get()
    {
        return "value";
    }
}

Then change your Launch browser to api/values

enter code here

Then it will work:

enter image description here

Share:
1,241

Related videos on Youtube

User5144
Author by

User5144

Updated on December 18, 2022

Comments

  • User5144
    User5144 over 1 year

    I followed the basic creation of the WEB API in .net core, and when I run the project, I am seeing

    This site can’t be reached The connection was reset. Try:

    Checking the connection Checking the proxy and the firewall Running Windows Network Diagnostics ERR_CONNECTION_RESET

    my launchsettings.json is as below

     {
      "iisSettings": {
      "windowsAuthentication": false, 
      "anonymousAuthentication": true, 
      "iisExpress": {
      "applicationUrl": "http://localhost:14306",
      "sslPort": 44318
     }
     },
     "profiles": {
      "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
      },
       "InventoryService": {
       "commandName": "Project",
       "launchBrowser": true,
       "applicationUrl": "https://localhost:5001;http://localhost:5000",
       "environmentVariables": {
       "ASPNETCORE_ENVIRONMENT": "Development"
       }
      }
    }
    }
    

    Not sure where I can check the proxy setting or if I am missing anything, I tried different solutions but none of them worked. this is my first time creating a project in .net core. Can you please help.

    And in Startup.cs I added this code.

       public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }
    
            app.UseHttpsRedirection();
            app.UseMvc();
    
        }
    

    Update

    I updated the port number and installed a self signed certificate,

    In my properties i updated the port

    changed the port number in the debug section

    Now I am seeing

    This localhost page can’t be found No webpage was found for the web address: https://localhost:5001/ HTTP ERROR 404

    my current state

    • Bryan Lewis
      Bryan Lewis about 4 years
      We need more information. I assume you're running Visual Studio? v2019? Did you do anything other than create the project from the template and hit Debug? Or did you change/add code? Is the project setup to run on HTTPS?
    • User5144
      User5144 about 4 years
      Hi Bryan, thanks for responding, I am running in 2017, where do I check if this project is set up to run on https. in Startup.cs, I did add above code.
    • Devon
      Devon over 3 years
      Seems to be an issue with age-restricted videos: github.com/ytdl-org/youtube-dl/issues/26152