• <bdo id='iL4iQ'></bdo><ul id='iL4iQ'></ul>
  1. <i id='iL4iQ'><tr id='iL4iQ'><dt id='iL4iQ'><q id='iL4iQ'><span id='iL4iQ'><b id='iL4iQ'><form id='iL4iQ'><ins id='iL4iQ'></ins><ul id='iL4iQ'></ul><sub id='iL4iQ'></sub></form><legend id='iL4iQ'></legend><bdo id='iL4iQ'><pre id='iL4iQ'><center id='iL4iQ'></center></pre></bdo></b><th id='iL4iQ'></th></span></q></dt></tr></i><div id='iL4iQ'><tfoot id='iL4iQ'></tfoot><dl id='iL4iQ'><fieldset id='iL4iQ'></fieldset></dl></div>
    <legend id='iL4iQ'><style id='iL4iQ'><dir id='iL4iQ'><q id='iL4iQ'></q></dir></style></legend>

  2. <tfoot id='iL4iQ'></tfoot>

      <small id='iL4iQ'></small><noframes id='iL4iQ'>

    1. 方法 'UseRouting' 没有重载需要 1 个参数

      时间:2023-07-10

      <small id='B4jR9'></small><noframes id='B4jR9'>

      • <bdo id='B4jR9'></bdo><ul id='B4jR9'></ul>
            <tbody id='B4jR9'></tbody>

            <i id='B4jR9'><tr id='B4jR9'><dt id='B4jR9'><q id='B4jR9'><span id='B4jR9'><b id='B4jR9'><form id='B4jR9'><ins id='B4jR9'></ins><ul id='B4jR9'></ul><sub id='B4jR9'></sub></form><legend id='B4jR9'></legend><bdo id='B4jR9'><pre id='B4jR9'><center id='B4jR9'></center></pre></bdo></b><th id='B4jR9'></th></span></q></dt></tr></i><div id='B4jR9'><tfoot id='B4jR9'></tfoot><dl id='B4jR9'><fieldset id='B4jR9'></fieldset></dl></div>
            <legend id='B4jR9'><style id='B4jR9'><dir id='B4jR9'><q id='B4jR9'></q></dir></style></legend>

                <tfoot id='B4jR9'></tfoot>
                本文介绍了方法 'UseRouting' 没有重载需要 1 个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我刚刚更新到 ASP.NET Core 3 Preview 5,现在当我打开我的解决方案并尝试构建它时会抛出错误在 Configure() 的 Startup.cs 文件中,方法 'UseRouting' 没有重载需要 1 个参数",代码如下:

                I just updated to ASP.NET Core 3 Preview 5, now when I open my solution and try to build it throws the error 'No overload for method 'UseRouting' takes 1 arguments' in the Startup.cs file in the Configure() at the following code:

                    app.UseRouting(routes => {
                        routes.MapControllerRoute(
                            name: "default",
                            template: "{controller=Home}/{action=Index}/{id?}");
                        routes.MapRazorPages();
                    });
                

                我确实阅读了有关 Microsoft 文档的一些文档,并尝试将上面的代码替换为:

                I did read some documentation on the Microsoft docs and tried replacing the above code with:

                    app.UseEndpoints(endpoints => {
                        endpoints.MapControllerRoute(
                            name: "default",
                            pattern: "{controller=Home}/{action=Index}/{id?}");
                        endpoints.MapRazorPages();
                    });
                

                但是,在构建期间会抛出具有以下上下文的 System.InvalidOperationException:

                However, during build time that throws an System.InvalidOperationException with the following context:

                'EndpointRoutingMiddleware 匹配端点设置EndpointMiddleware 等必须添加到请求执行中EndpointMiddleware 之前的管道.请加EndpointRoutingMiddleware 通过调用IApplicationBuilder.UseRouting"在应用程序启动代码中对Configure(...)"的调用中.

                'EndpointRoutingMiddleware matches endpoints setup by EndpointMiddleware and so must be added to the request execution pipeline before EndpointMiddleware. Please add EndpointRoutingMiddleware by calling 'IApplicationBuilder.UseRouting' inside the call to 'Configure(...)' in the application startup code.'

                我尝试在 ConfigureServices 方法中替换以下行:

                I tried replacing the following line in the ConfigureServices method:

                    services.AddMvc()
                        .AddNewtonsoftJson();
                

                宽度:

                    services.AddControllersWithViews()
                        .AddNewtonsoftJson();
                    services.AddRazorPages();
                

                这不会再引发错误,但我的页面在完成加载时是空白的.谁能帮我解决这个问题?

                This does not throw errors anymore but my page is blank when it finishes loading. Who can help me solve this issue?

                对于我的解决方案,我使用以下软件包:

                For my solution I use the following packages:

                 <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.0.0-preview5-19227-01" />
                    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0-preview5-19227-01" />
                    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0-preview5-19227-01" />
                    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0-preview5-19227-01" />
                    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0-preview5.19227.1" />
                    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0-preview5.19227.1">
                      <PrivateAssets>all</PrivateAssets>
                      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
                    </PackageReference>
                    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0-preview5.19227.9" />
                    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
                

                我的解决方案的 TargetFramework 是 netcoreapp3.0

                The TargetFramework of my solution is netcoreapp3.0

                推荐答案

                再次引用错误信息:

                EndpointRoutingMiddleware 匹配 EndpointMiddleware 设置的端点,因此必须在 EndpointMiddleware 之前添加到请求执行管道中.请通过在应用程序启动代码中对Configure(...)"的调用中调用IApplicationBuilder.UseRouting"来添加EndpointRoutingMiddleware.

                EndpointRoutingMiddleware matches endpoints setup by EndpointMiddleware and so must be added to the request execution pipeline before EndpointMiddleware. Please add EndpointRoutingMiddleware by calling 'IApplicationBuilder.UseRouting' inside the call to 'Configure(...)' in the application startup code.

                ASP.NET Core 3 使用改进的端点路由,这通常会在应用程序中提供更多关于路由的控制.端点路由分为两个独立的步骤:

                ASP.NET Core 3 uses a refined endpoint routing which will generally give more control about routing within the application. Endpoint routing works in two separate steps:

                • 第一步,将请求的路由与配置的路由进行匹配,以确定正在访问的路由.
                • 在最后一步中,正在评估确定的路由以及相应的中间件,例如MVC,被调用.

                这是允许其他中间件在这些点之间起作用的两个独立步骤.这允许这些中间件利用来自端点路由的信息,例如处理授权,而不必作为实际 handler(例如 MVC)的一部分执行.

                These are two separate steps to allow other middlewares to act between those points. That allows those middlewares to utilize the information from endpoint routing, e.g. to handle authorization, without having to execute as part of the actual handler (e.g. MVC).

                这两个步骤由app.UseRouting()app.UseEndpoints()设置.前者将注册运行逻辑以确定路由的中间件.然后后者将执行该路由.

                The two steps are set up by app.UseRouting() and app.UseEndpoints(). The former will register the middleware that runs the logic to determine the route. The latter will then execute that route.

                如果你仔细阅读错误信息,在 EndpointRoutingMiddlewareEndpointMiddleware 的用法有点混乱,它会告诉你添加 UseRouting() Configure 方法的内部.所以基本上,你忘了调用端点路由的第一步.

                If you read the error message carefully, between the somewhat confusing usage of EndpointRoutingMiddleware and EndpointMiddleware, it will tell you to add UseRouting() inside of the Configure method. So basically, you forgot to invoke the first step of endpoint routing.

                所以您的 Configure 应该(例如)如下所示:

                So your Configure should (for example) look like this:

                app.UseRouting();
                
                app.UseAuthentication();
                
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllerRoute(
                        name: "default",
                        pattern: "{controller=Home}/{action=Index}/{id?}");
                    endpoints.MapRazorPages();
                });
                

                到 3.0 的路由迁移也记录在 3.0 迁移指南.

                The routing migration to 3.0 is also documented in the migration guide for 3.0.

                这篇关于方法 'UseRouting' 没有重载需要 1 个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 ASP.NET Core 中实现自定义模型验证? 下一篇:如何使用 DI 在类构造函数中获取 Microsoft.AspNet.Http.HttpContext 实例

                相关文章

                <legend id='bwkwf'><style id='bwkwf'><dir id='bwkwf'><q id='bwkwf'></q></dir></style></legend>

                <small id='bwkwf'></small><noframes id='bwkwf'>

                  <bdo id='bwkwf'></bdo><ul id='bwkwf'></ul>

                <tfoot id='bwkwf'></tfoot>

                  <i id='bwkwf'><tr id='bwkwf'><dt id='bwkwf'><q id='bwkwf'><span id='bwkwf'><b id='bwkwf'><form id='bwkwf'><ins id='bwkwf'></ins><ul id='bwkwf'></ul><sub id='bwkwf'></sub></form><legend id='bwkwf'></legend><bdo id='bwkwf'><pre id='bwkwf'><center id='bwkwf'></center></pre></bdo></b><th id='bwkwf'></th></span></q></dt></tr></i><div id='bwkwf'><tfoot id='bwkwf'></tfoot><dl id='bwkwf'><fieldset id='bwkwf'></fieldset></dl></div>