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

妖精的绣舞 提交于 2020-01-25 00:19:05

问题


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


回答1:


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();
    });`


来源:https://stackoverflow.com/questions/58845286/after-upgrade-to-net-core-3-0-errorno-webpage-was-found-for-the-web-address-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!