升级到.net core 3.0 后报错"No webpage was found for the web address: https://localhost:44374/"

after upgrade to .net core 3.0 error"No webpage was found for the web address: https://localhost:44374/"

我将具有 2 个 类 库和一个 Mvc 项目的项目从 2.2 升级到 MVC Core 3.0 惠特这个页面 enter link description here

  1. 更改 .net <TargetFramework>netcoreapp3.0</TargetFramework>

    2.change这样

    <ItemGroup> <!--<PackageReference Include="Microsoft.AspNetCore.App" />--> <!--<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />--> <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0" /> <!--<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />--> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" /> </ItemGroup>

    3.my satrtup.cs

    `
    app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseDefaultFiles(); app.UseCookiePolicy();

        app.UseRouting();
    
        app.UseAuthorization();
    
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapRazorPages();
        });`
    
  2. 我的program.cs

    public static void Main(string[] args) { CreateHostBuilder(args).Build().运行(); } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(参数) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); });

但是当我 运行 我的项目得到这个错误

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

Startup.cs 试试这个

public void ConfigureServices(IServiceCollection services) 
{
           //Code above . . .

            services.AddMvc( options =>
            {
                options.EnableEndpointRouting = false;
            });

            //Code below. . .
}

然后在

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            //Code above . . .

            app.UseMvcWithDefaultRoute();

            //Code below. . .
        }

并删除

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapRazorPages();
    });`