gpt4 book ai didi

c# - 升级到 .net core 3.0 后报错“找不到网页地址为 : https://localhost:44374/"的网页

转载 作者:行者123 更新时间:2023-12-04 13:39:56 24 4
gpt4 key购买 nike

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

  • 更改.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.my sattup.cs

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

    app.UseAuthorization();

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

    public static void Main(string[] args)
    {
    CreateHostBuilder(args).Build().Run();
    }
    公共(public)静态 IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
    .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();
    });`

    关于c# - 升级到 .net core 3.0 后报错“找不到网页地址为 : https://localhost:44374/"的网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58845286/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com