Reputation: 30081
I'm implementing a new class library's settings and I'm wanting to use .NET 2.0's settings architecture, instead of the regular appSettings
section in a .config
file.
I've created a Main.settings
file through the Visual Studio 2008 IDE, and this has autogenerated both the Main.settings
file and a corresponding Main.Designer.cs
file. In the IDE, I have to select between whether each setting should have User scope or Application scope, which translates to the IDE applying either UserScopedSettingAttribute
or ApplicationScopedSettingAttribute
to the setting's Property.
The stuff on MSDN I've found on the topic seems to come at things from the point of view of a Windows Forms application; it talks about using user-scoped settings for stuff which pertains just to the user using the app, and application-scoped settings for stuff which always pertains to the app, no matter which user is using it.
However, what should I do when my settings file isn't for a Windows Forms app, but for a class library that I'm calling from a website under IIS? Does it matter whether I scope the settings as User or Application? If so, what factors are there to take into account as to how I should scope the settings?
Upvotes: 1
Views: 2104
Reputation: 2185
Web applications do not support user scoped application settings. To get similar functionality, you could use the SettingsProvider class or create your own implementation of it. For application-wide settings, you will have to use the web.config file and either
The answer to your second question is: it depends.
In a web app, user-scoped settings are usually associated with a session and allow for each user to have a different value for a particular setting. These settings are usually used to customize a user's experience. On the other hand, if you want a setting to be the same application-wide regardless of the user who is accessing the application, you should be using an application-scoped setting.
If you provide more detail regarding your specific situation, I may be able to provide further guidance.
Also, take a look at this question if you want to use a config file from the class library instead of placing your settings in the web.config file.
Upvotes: 1