App.config : 사용자 대 애플리케이션 범위
내 프로젝트에 App.config 파일을 추가했습니다. 프로젝트> 속성> 설정 패널에서 두 가지 설정을 만들었습니다.
설정을 추가 할 때 범위를 User
또는 로 정의 할 수 있습니다 Application
. -
- 사용자
- 신청
I는 다음과 같이 설정 정의하는 경우 User
가 간다 userSettings
, 섹션
내가 설정을 정의하는 경우로 Application
이가는 applicationSettings
부분
App.config
<configuration>
<userSettings>
<DemoApp.Properties.Settings>
<setting name="MySetting1" serializeAs="String">
<value>Value1</value>
</setting>
</DemoApp.Properties.Settings>
</userSettings>
<applicationSettings>
<DemoApp.Properties.Settings>
<setting name="MySetting2" serializeAs="String">
<value>Value2</value>
</setting>
</DemoApp.Properties.Settings>
</applicationSettings>
</configuration>
그러나, 이러한 설정에서 같은 방법으로 액세스 할 수 있습니다 .cs
-
암호
string mySetting1 = DemoApp.Properties.Settings.Default.MySetting1;
string mySetting2 = DemoApp.Properties.Settings.Default.MySetting2;
User
과 Application
범위 의 차이점은 무엇이며 어떤 상황에서이 둘 중에서 선택해야합니까?
Basically, application settings cannot be changed during the running of a program and user settings can. These user settings should then be saved so the user is presented with a familiar experience when (s)he runs the application next.
Edit: For examples, you might write your application with different modules, and need to ensure that your main module is using the correct version of your security module. For this you would set up an application-scope setting eg:
SecurityModuleVersion string Application v1.21
Sometime later when you refactor the security module, you might change the value to v1.22 when you deploy to ensure the correct security is being implemented
On the other hand, if your application has different 'skins' with color changes, font changes etc, then you may setup a user setting something like the following:
ApplicationSkin string User DefaultSkin
Then, when Michelle changes to the skin she prefers, the application remembers her settings. The properties may now look like:
ApplicationSkin string User HelloKittySkin
Application-scope settings are read only, and can only be changed at design time or by altering the .exe.config file in between application sessions. User-scope settings, however, can be written at run time, just as you would change any property value. The new value persists for the duration of the application session. You can persist changes to user settings between application sessions by calling the Settings.Save method.
Source on msdn: Using Settings in C#
User settings are generally of use for persisting user preferences (e.g. app notification preferences etc.). Application settings would generally for items such as API keys etc.
@kmote에서 언급했듯이 사용자 설정이 런타임에 수정되고 유지되면 (을 통해 settings.Save()
) 사용자 프로필 저장소 내의 폴더 (일반적으로 Windows 7 이상에서는 C : \ Users \ Username \ AppData \ Local \ AppName)에 기록 됩니다. ). 프로그래밍 방식으로 파일의 위치를 확인하려면 이 게시물을 참조하십시오 .
참고 URL : https://stackoverflow.com/questions/13046907/app-config-user-vs-application-scope
'developer tip' 카테고리의 다른 글
Redis 및 Memcache 또는 Redis? (0) | 2020.09.19 |
---|---|
Json.net은 파생 유형을 직렬화 / 역 직렬화합니까? (0) | 2020.09.19 |
목록의 모든 문자열을 변환하는 방법 (0) | 2020.09.18 |
SSRS 2008 R2-SSRS 2012-ReportViewer : Safari 및 Chrome에서 보고서가 비어 있습니다. (0) | 2020.09.18 |
Git / Bower 오류 : 종료 코드 # 128 및 연결 실패 (0) | 2020.09.18 |