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

1

5

I upgrade my project that have 2 classes library and one Mvc project to MVC Core 3.0 from 2.2 whit this page enter link description here

  1. change .net <TargetFramework>netcoreapp3.0</TargetFramework>

    2.change like this

    <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. My program.cs

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

but when I run my project get this error

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

Meiosis answered 13/11, 2019 at 20:40 Comment(0)
H
2

in Startup.cs try this

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

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

            //Code below. . .
}

and then in

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

            app.UseMvcWithDefaultRoute();

            //Code below. . .
        }

and remove

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapRazorPages();
    });`
Hoodoo answered 13/11, 2019 at 20:44 Comment(3)
I honestly don't know. I think Microsoft Migration example is for a RazorPages example, not MVC. When we migrated, we use MVC and I ran into this exact problem, and this is how I fixed it.Hoodoo
If you end up figuring out why, would you mind posting it back here?Hoodoo
another think, it work fine, when run local , but when publish in local folder get this error: Assets file '..\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.2'. Ensure that restore has run and that you have included 'netcoreapp2.2' in the TargetFrameworks for your project.Meiosis

© 2022 - 2024 — McMap. All rights reserved.