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
我将它们定义为user (scope),但我正在获取
System.Configuration.ConfigurationErrorsException: The current configuration system does not support user-scoped settings.
System.Configuration。ConfigurationErrorsException:当前的配置系统不支持用户范围的设置。
What may be a good solution?
什么是好的解决方案?
3 个解决方案
#1
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.
用户范围的设置实际上不支持Web应用程序。它们不能工作,用户设置必须保存在Users\
You have a wide choice of web techniques:
您有广泛的网络技术选择:
- persistent cookies
- 持续的饼干
- ASP.NET Membership profiles
- ASP。网会员资料
- your own Db
- 你自己的数据库
#2
14
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.
当我遇到这个问题时,我发现我有一个对具有设置的dll的引用。设置(或Settings.Designer.cs)文件。
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.
当编辑设置时。设置文件,当单击底部的空行时,将添加一个新的行,其中包含模板信息和默认的用户设置,而不是应用程序设置。这是一个很好的特性,但是您可以看到,在更改模板并添加新设置之后,单击下面以失去焦点,将添加一个新的模板行,如果您不注意,您将意外地添加一个用户设置。检查这个文件是否在引用的dll中,并删除任何用户设置。
#3
2
You can make Application scope settings writable by simply adding a setter to the property definition in Settings.Designer.cs
. For instance:
您可以通过在Settings.Designer.cs. cs中向属性定义添加一个setter来使应用程序范围设置可写入。例如:
[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.
需要注意的是,Settings.Designer。cs是自动生成的,因此如果您使用设计器UI,您的setter将被覆盖。
This works in console and web applications.
这适用于控制台和web应用程序。
#1
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.
用户范围的设置实际上不支持Web应用程序。它们不能工作,用户设置必须保存在Users\
You have a wide choice of web techniques:
您有广泛的网络技术选择:
- persistent cookies
- 持续的饼干
- ASP.NET Membership profiles
- ASP。网会员资料
- your own Db
- 你自己的数据库
#2
14
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.
当我遇到这个问题时,我发现我有一个对具有设置的dll的引用。设置(或Settings.Designer.cs)文件。
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.
当编辑设置时。设置文件,当单击底部的空行时,将添加一个新的行,其中包含模板信息和默认的用户设置,而不是应用程序设置。这是一个很好的特性,但是您可以看到,在更改模板并添加新设置之后,单击下面以失去焦点,将添加一个新的模板行,如果您不注意,您将意外地添加一个用户设置。检查这个文件是否在引用的dll中,并删除任何用户设置。
#3
2
You can make Application scope settings writable by simply adding a setter to the property definition in Settings.Designer.cs
. For instance:
您可以通过在Settings.Designer.cs. cs中向属性定义添加一个setter来使应用程序范围设置可写入。例如:
[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.
需要注意的是,Settings.Designer。cs是自动生成的,因此如果您使用设计器UI,您的setter将被覆盖。
This works in console and web applications.
这适用于控制台和web应用程序。