升级到 .net core 3.0 后出现错误“未找到该网址的网页:https://localhost:44374/”

2024-03-27

我将具有 2 个类库和 1 个 Mvc 项目的项目从 2.2 升级到 MVC Core 3.0 这一页

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

    2.这样改

    <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.我的startup.cs

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

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

    公共静态无效主要(字符串[]参数) { CreateHostBuilder(args).Build().Run(); } 公共静态 IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); });

但是当我运行我的项目时出现此错误

无法找到此本地主机页面未找到该网址的网页:https://本地主机:44374/ https://localhost:44374/HTTP 错误 404


in 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();
    });`
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

升级到 .net core 3.0 后出现错误“未找到该网址的网页:https://localhost:44374/” 的相关文章

随机推荐