I need to run some c# code each time any page based on _layout.cshtml is viewed. I don\'t want to put something in every controller.cs file, just something central like yo
Filter would also work, but the correct way to go in .Net Core is Middleware. You can read more about it here.
If it's something simple as your example, you can go with the first examples on the link like:
app.Use(async (context, next) =>
{
returnTrue();
await next.Invoke();
});
Let me know if it helped!