Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core This localhost page can’t be found

Does anyone encountered this kind of problem? I think it has something to do with the IIS or so... I am using IIS 10 also using VS2017 and ASP.NET Core. When I launch the application I saw this error:

This localhost page can’t be found

No webpage was found for the web address: http://localhost:44306/

I tried changing the port. But nothing works. I tried other application it works but only this project having this kind of error and I don't know why.

Any Idea how to fix this?

Update:

like image 220
Alvin Quezon Avatar asked Apr 18 '17 09:04

Alvin Quezon


Video Answer


2 Answers

I solved this problem when I realized I had accidentially removed the default route in the StartUp class' Configure method:

        app.UseMvc(routes =>         {             routes.MapRoute(                 name: "default",                 template: "{controller=Home}/{action=Index}/{id?}");         }); 
like image 170
TimewiseGamgee Avatar answered Sep 28 '22 04:09

TimewiseGamgee


This is similar to @ToMissTheMarc answer, but shows how to define routes in .Net Core version 3.0

I was having a similar problem when trying to hit my API endpoint https://localhost:44380/api/Restaurants

In order to map my routes for an API controller class that inherited from the ControllerBase class, I needed to add the line endpoints.MapControllers to Configure method of Startup.cs class, as follows:

        //Pre .NET core 3.0 way of doing things         //app.UseMvc(routes => {<some routing stuff here>});          //.NET core 3.0 way         app.UseRouting();         app.UseEndpoints(endpoints =>         {             endpoints.MapRazorPages(); //Routes for pages             endpoints.MapControllers(); //Routes for my API controllers         }); 
like image 38
michaela112358 Avatar answered Sep 28 '22 03:09

michaela112358