.net core 2.1 VS 2017 basic web api throwing "this site can't be reached"
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:
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
Then it will work:
Related videos on Youtube
User5144
Updated on December 18, 2022Comments
-
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
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
-
Bryan Lewis about 4 yearsWe 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 about 4 yearsHi 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 over 3 yearsSeems to be an issue with age-restricted videos: github.com/ytdl-org/youtube-dl/issues/26152
-