gpt4 book ai didi

c# - 使用 C# 设置和 LocalFileSettingsProvider 时公司名称中的下划线

转载 作者:可可西里 更新时间:2023-11-01 14:37:21 28 4
gpt4 key购买 nike

我注意到,当使用由 Windows 窗体应用程序创建的设置对象时,程序集信息的“公司名称”字段中的所有空格都被 user.config 文件路径中的下划线替换。例如,在 XP 中,user.config 文件的路径类似于:

\Documents and Settings\user\Local Settings\Application Data\Company_Name_Here\App\Version\user.config

但这似乎只发生在我自己的应用程序上。我的机器上安装了很多 .NET 应用程序,但应用程序数据下的其他目录名称均不包含下划线(保留空格)。

什么给了?这没什么大不了的,但我只是想知道为什么这似乎只发生在我的应用程序中,以及是否有一种方法可以改变我不知道的这种行为。

最佳答案

Quoting在微软工作的人

<Company Name> - is typically the string specified by the AssemblyCompanyAttribute (with the caveat that the string is escaped and truncated as necessary, and if not specified on the assembly, we have a fallback procedure).

Q: Why is the path so obscure? Is there any way to change/customize it?

A: The path construction algorithm has to meet certain rigorous requirements in terms of security, isolation and robustness. While we tried to make the path as easily discoverable as possible by making use of friendly, application supplied strings, it is not possible to keep the path totally simple without running into issues like collisions with other apps, spoofing etc.

The LocalFileSettingsProvider does not provide a way to change the files in which settings are stored. Note that the provider itself doesn't determine the config file locations in the first place - it is the configuration system. If you need to store the settings in a different location for some reason, the recommended way is to write your own SettingsProvider. This is fairly simple to implement and you can find samples in the .NET 2.0 SDK that show how to do this. Keep in mind however that you may run into the same isolation issues mentioned above .

可能会给出一些解释。

因此其他应用程序可能使用了支持空格的单独设置提供程序。

还提到了默认 .NET 设置提供程序的限制 here :

Each application setting must have a unique name; the name can be any combination of letters, numbers, or an underscore that does not start with a number, and cannot contain spaces. The name can be changed through the Name property.

关于c# - 使用 C# 设置和 LocalFileSettingsProvider 时公司名称中的下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1717077/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com