I'm trying to use a settings file to store the user preferences when he/she logins on the application.
I defined them as user (scope) but I am getting
System.Configuration.ConfigurationErrorsException: The current configuration system does not support user-scoped settings.
What may be a good solution?
When I had this problem, it turned out that I had a reference to a dll which had a Settings.settings (or Settings.Designer.cs) file.
What happens is that when editing the Setting.settings file, upon clicking the blank line at the bottom, a new line is added with template information and a default user setting instead of application setting. This is a nice feature but you could see how after changing the template and adding your new setting, then clicking below to lose focus a new template line is added and if you are not paying attention, you accidently add a user setting. Check if you have this file in a referenced dll and remove any user settings.
User-scoped settings are indeed not supported for a Web application. And they wouldn't work, User settings would have to be saved under the Users\<username>\...
folder on the server.
You have a wide choice of web techniques:
You can make Application scope settings writable by simply adding a setter to the property definition in Settings.Designer.cs
. For instance:
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("AdminContext")]
public string DbContext
{
get { return ((string)(this["DbContext"])); }
set { this["DbContext"] = value; } }
The caveat is that the Settings.Designer.cs
is auto-generated, and therefore if you use the designer UI, your setters will be overwritten.
This works in console and web applications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With