user.config问题释疑

本文详细解释了应用程序如何使用配置文件来为不同用户提供定制化的设置,并介绍了配置文件的同步及默认值生成方式。同时探讨了代码中放置敏感信息的安全考虑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

What exactly is it that you're trying to achieve? I was under the impression that you wanted to show a welcome screen the first time a user ran the application. Is that not your intention?
Note that the application config file contains the default value for all User-scoped settings. These default values are used to generate a user-specific config file under the currrent user's Documents and Settings folder, which is how each user can have different values for those settings. When you run your app it checks whether the current user already has a config file. If they do then it is used. If they don't then one is generated from the default values in the application config file.
Once you've debugged your app for the first time it will have generated a user config file and that value will be used every time you run the app thereafter. If you want to clear all user config files then you go to the Settings tab in the project properties and click the Synchronize button. This will delete all user config files and you start afresh with all default values. Obviously when you distribute your app your users will not have a config file already so they will see the welcome screen the first run.
What that GenerateDefaultValueInCode property does is determine whether the default value is placed in your VB code as well as your config file, or just in your config file. One reason you might care is that the config file can be encrypted to protect sensitive data, while if something like a connection string is placed in your VB code as well it might be found through decompilation. The advantage of having it in code is that the end user can't edit it, which they can if it is just in the config file. Here's an example of the code for a setting in the Settings.Designer.vb file with that property set to False:

VB Code:

  1. <Global.System.Configuration.UserScopedSettingAttribute(),  _

  2.          Global.System.Diagnostics.DebuggerNonUserCodeAttribute()>  _

  3.         Public Property Setting() As String

  4.             Get

  5.                 Return CType(Me("Setting"),String)

  6.             End Get

  7.             Set

  8.                 Me("Setting") = value

  9.             End Set

  10.         End Property

Here's the corresponding code with the property set to True:

VB Code:

  1. <Global.System.Configuration.UserScopedSettingAttribute(),  _

  2.          Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),  _

  3.          Global.System.Configuration.DefaultSettingValueAttribute("DefaultSettingValue")>  _

  4.         Public Property Setting() As String

  5.             Get

  6.                 Return CType(Me("Setting"),String)

  7.             End Get

  8.             Set

  9.                 Me("Setting") = value

  10.             End Set

  11.         End Property

If that setting contained something like a password it would be visible to anyone who decompiled your assembly. An encrypted config file would be much more secure.

转载于:https://www.cnblogs.com/shanghaif/archive/2008/12/26/1362742.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值