简体   繁体   中英

Managing global settings in an ASP.NET MVC application?

I am developing an ASP.NET MVC 5 application and I need to manage some global parameters, which are basically just a set of key-value-pairs. My requirements are the following:

  1. Initial values are read from a server config file.
  2. Parameters are available in every controller for both reading/writing and adding/deleting (like a new parameter can be added if certain controller is executed).
  3. Parameters should surface subsequent request (either residing in Session or serialized in QueryString ).
  4. I should be possible to see and easily manage them (CRUD) using a special admin webpage.

My "brute force" approach for this would be just to implement a static class with List<Tuple<string,string>> to keep the settings, use System.Web.Configuration.WebConfigurationManager to populate initial values, use static properties to store and retrieve the list in a session variable and design a separate controller and view for managing the settings.

But this looks like re-inventing the wheel to me. Is there any (not necessarily full-fledged) pre-existing solution (in ASP.NET, or as a NuGet package) I might rest my efforts upon? Or maybe I am missing something fundamental in ASP.NET?

UPDATE : Depending on the nature of the parameter, some of them might have the lifetime of the Application , whereas some of them are bound to the current user session. Therefore they need to be either preserved in a Session object or "passed through" in every request.

这听起来像是最常见的方法,我认为使用会话变量没有任何问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM