MVC CORE 2.0.0 run c# code on every page

后端 未结 2 2013
你的背包
你的背包 2021-01-07 11:00

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

2条回答
  •  伪装坚强ぢ
    2021-01-07 11:56

    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!

提交回复
热议问题