ASP.NET Core无法找到此localhost页面

Alv*_*zon 16 iis asp.net-core-mvc

有没有人遇到过这种问题?我认为它与IIS有关...我正在使用IIS 10也使用VS2017和ASP.NET Core.当我启动应用程序时,我看到了这个错误:

找不到此localhost页面

找不到网址的网页:http:// localhost:44306 /

我试过改变端口.但没有任何作用.我尝试了其他应用程序它的工作,但只有这个项目有这种错误,我不知道为什么.

任何想法如何解决这个问题?

更新:

ToM*_*arc 20

当我意识到我在StartUp类的Configure方法中意外删除了默认路由时,我解决了这个问题:

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
Run Code Online (Sandbox Code Playgroud)


小智 16

这类似于@ToMissTheMarc 答案,但展示了如何在 .Net Core 3.0 版中定义路由

我在尝试访问我的 API 端点 https://localhost:44380/api/Restaurants 时遇到了类似的问题

为了映射从类继承的 API 控制器类的路由ControllerBase,我需要将行添加endpoints.MapControllers到类的Configure方法Startup.cs,如下所示:

        //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
        });
Run Code Online (Sandbox Code Playgroud)


Sar*_*rif 6

我遇到了同样的问题,但这个错误是一个愚蠢的错误,因此解决方案非常简单!我的路线中有一个拼写错误,我在控制器名称后错误地添加了一个空格,我知道它不是很技术性的答案,但仔细检查不会有什么坏处

曾是:

app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("Default", "{controller= Home}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)

更正为:

app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("Default", "{controller=Home}/{action=Index}/{id?}"); 
});
Run Code Online (Sandbox Code Playgroud)


小智 5

如果上述答案不起作用,或者您来自.NET Web API教程,则可能会有所帮助。所以对我来说,我删除了该launchUrl属性,launchSettings.json因为我想使用静态页面(按照我遵循的教程说明),却忘记匆匆添加两行。我终于回过头来查看它,这解决了我的问题。

打开Startup.cs文件,然后在行public void Configure...上方添加以下内容app.UseMvc();

app.UseDefaultFiles(); app.UseStaticFiles();