• ASP.NET Core 3.0 中 app.UseRouting 与 app.UseEndpoints


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

    • In a first step, the requested route is matched agains the configured routes to figure out what route is being accessed.
    • In a final step, the determined route is being evaluated and the respective middleware, e.g. MVC, is called.

      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).

      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.

      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.

    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();
    });
  • 相关阅读:
    Codeforces Round #271 (Div. 2) F. Ant colony 线段树
    poj 1744 tree 树分治
    HDU Shell Necklace CDQ分治+FFT
    BZOJ 1567: [JSOI2008]Blue Mary的战役地图 矩阵二维hash
    BZOJ 1042: [HAOI2008]硬币购物 容斥+背包
    HDU 6078 Wavel Sequence 树状数组优化DP
    Gym
    HDU 6058 Kanade's sum 二分,链表
    HDU 6061 RXD and functions NTT
    ZOJ 3233 Lucky Number 容斥原理
  • 原文地址:https://www.cnblogs.com/kest/p/13495329.html
Copyright © 2020-2023  润新知