Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 320
Alexander Galkin Avatar asked Dec 06 '25 05:12

Alexander Galkin


1 Answers

That sounds like the most common approach, I don't see anything wrong with using session variables.

like image 146
Dassina Avatar answered Dec 08 '25 19:12

Dassina



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!