【问题标题】:after upgrade to .net core 3.0 error"No webpage was found for the web address: https://localhost:44374/"升级到 .net core 3.0 后出现错误“没有找到网址的网页:https://localhost:44374/”
【发布时间】:2020-03-09 17:36:06
【问题描述】:

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

  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.my satrtup.cs

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

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

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

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

找不到此本地主机页面没有找到该网址的网页:https://localhost:44374/ HTTP 错误 404

【问题讨论】:

    标签: c# asp.net-core-mvc upgrade .net-core-3.0


    【解决方案1】:

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

    【讨论】:

    • 我真的不知道。我认为 Microsoft Migration 示例适用于 RazorPages 示例,而不是 MVC。当我们迁移时,我们使用 MVC,我遇到了这个确切的问题,这就是我修复它的方法。
    • 如果你最终找出原因,你介意把它发回这里吗?
    • 另一种想法,当运行 local 时它工作正常,但是当在本地文件夹中发布时出现此错误:Assets file '..\obj\project.assets.json' doesn't have a target for '.NETCoreApp,版本 = v2.2'。确保恢复已运行,并且您已在项目的 TargetFrameworks 中包含“netcoreapp2.2”。
    猜你喜欢
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    • 2018-05-31
    • 1970-01-01
    • 2021-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多