What are the differences between app.UseRouting() and app.UseEndPoints()?

后端 未结 5 916
忘掉有多难
忘掉有多难 2021-01-31 14:48

As I\'m trying to understand them, It seem like they are both used to route/map the request to a certain endpoint

5条回答
  •  时光取名叫无心
    2021-01-31 15:12

    Based dotnet core documentation:

    ╔══════════════════════════════════════════╦═══════════════════════════════════════╗
    ║             app.UseRouting()             ║          app.UseEndPoints()           ║
    ╠══════════════════════════════════════════╬═══════════════════════════════════════╣
    ║               Find Endpoint              ║           Execute Endpoint            ║
    ║                                          ║                                       ║
    ║  Adds route matching to the middleware   ║  Adds endpoint execution to the       ║
    ║  pipeline. This middleware looks at the  ║  middleware pipeline.                 ║
    ║  set of endpoints defined in the app,    ║  It runs the delegate associated      ║
    ║  and selects the best match based        ║  with the selected endpoint.          ║
    ║  on the request.                         ║                                       ║
    ║                                          ║                                       ║
    ╚══════════════════════════════════════════╩═══════════════════════════════════════╝
    

    Based above table we should take care about some tips:

    1. If the app calls UseStaticFiles, place UseStaticFiles before UseRouting.

    2. it's important that you place the Authentication and Authorization middleware between UseRouting and UseEndPoints .

    3. Any middleware that appears after the UseRouting() call will know which endpoint will run eventually.

    4. Any middleware that appears before the UseRouting() call won't know which endpoint will run eventually.

提交回复
热议问题