Conditionally disable ASP.NET MVC Controller

后端 未结 3 903
终归单人心
终归单人心 2020-12-11 15:22

What is the best way to disable ASP.NET MVC controller conditionally?

I want to have an access to the controller actions if some value in web.config is \"true\" and

3条回答
  •  猫巷女王i
    2020-12-11 15:45

    The easiest would probably be to implement a custom action filter:

    http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/understanding-action-filters-cs

    You can also conditionally add a route that matches that controller that would result in a 404 being returned.

提交回复
热议问题