【发布时间】:2019-07-04 21:34:21
【问题描述】:
在我的应用程序中,我有简单的登录页面,带有 IP 地址/登录名/密码/记住我检查器。
当我检查记住我时,应用程序将这些数据存储在文件中:C:\Users\user\AppData\Local\App\App.exe_Url_5b4qolbj3ip4ltms1ohyh4cdivud5wfg\1.0.0.0\user.config
这对我来说完全没问题,但问题是(我不知道为什么会这样)当我构建我的 SetupWizard.msi 时,这个 user.config 是由 app 文件夹中的应用程序创建的。
然后当我执行程序并选中记住我框时,它不会将值存储在这个应用程序创建的 user.config 中,但它仍然存储在 AppData 文件中。
有什么办法可以摆脱应用程序文件夹中的 user.config 并将其仅存储在 AppData 中?另一个主要原因是这个(由安装创建的)配置文件有两个扩展名:App.exe.config。我不可能在发布时就这样离开它。
保存代码
public void Save_data()
{
if (CheckBoxRemCredts.IsChecked == true)
{
Properties.Settings.Default.userName = txtBoxLogin.Text;
Variable.passEncrypted = (Encrypt(pswBox.Password));
// MessageBox.Show(Variable.passEncrypted); Debugging
Properties.Settings.Default.userPass = Variable.passEncrypted;
Properties.Settings.Default.ipAddress = txtBoxIP.Text;
Properties.Settings.Default.Remme = "yes";
Properties.Settings.Default.Save();
}
else
{
Properties.Settings.Default.userName = txtBoxLogin.Text;
Properties.Settings.Default.userPass = pswBox.Password;
Properties.Settings.Default.ipAddress = txtBoxIP.Text;
Properties.Settings.Default.Remme = "no";
Properties.Settings.Default.Reset();
}
}
Settings.settings 文件:
namespace SMS_Vrána.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.7.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string userPass {
get {
return ((string)(this["userPass"]));
}
set {
this["userPass"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string Remme {
get {
return ((string)(this["Remme"]));
}
set {
this["Remme"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string ipAddress {
get {
return ((string)(this["ipAddress"]));
}
set {
this["ipAddress"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string userName {
get {
return ((string)(this["userName"]));
}
set {
this["userName"] = value;
}
}
}
}
【问题讨论】: