I'm currently migrating an ASP.Net MVC 6 app to Core Net6. In addition to the default Controller/Action/Id route, I'm creating an additional route that contains a customerkey in the URL:
app.MapControllerRoute(
name: "ManagingCustomer",
pattern: "{customerkey:int}/{controller=Home}/{action=Index}/{id?}");
app.MapControllerRoute(
name: "Default",
pattern: "{controller=Home}/{action=Index}/{id?}");
Within the app, a user can manage their own account or other accounts to which they have access. When they are managing an account other than their own, I would navigate with the prepended customerkey route data.
If a URL contains the customerkey route data item, where in the pipeline can I inject code to validate that the currently authenticated user actually has access to the requested account? I would like this run on every request and don't necessarily want to add code to every controller and action in order to support it. In the old MVC6 app, I would have done this in global.asax.cs. I just don't know where this fits in the core world. I'm guessing it falls into middleware? Any help would be appreciated. Thanks.