The current configuration system does not support user-scoped settings
Asked Answered
U

3

17

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?

Udella answered 25/3, 2012 at 21:53 Comment(0)
J
11

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:

  • persistent cookies
  • ASP.NET Membership profiles
  • your own Db
Jujitsu answered 25/3, 2012 at 22:10 Comment(0)
P
16

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.

enter image description here

Plastid answered 4/12, 2012 at 20:44 Comment(0)
J
11

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:

  • persistent cookies
  • ASP.NET Membership profiles
  • your own Db
Jujitsu answered 25/3, 2012 at 22:10 Comment(0)
U
3

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.

Undertaking answered 10/8, 2012 at 22:0 Comment(2)
Although this is not best practice, it does work and is fully tested. Given I caveat the approach in the body, I don't think it is valid to give a down vote. This solution is "use at your own risk" but nevertheless, it is a solution.Undertaking
Settings.Designer.cs is auto-generated. Not good solution.Papery

© 2022 - 2024 — McMap. All rights reserved.