这段代码有什么用? System.Configuration.ConfigurationManager.AppSettings [" CheckPassword"]; [英] What is the use of this code line ? System.Configuration.ConfigurationManager.AppSettings["CheckPassword"];

查看:109
本文介绍了这段代码有什么用? System.Configuration.ConfigurationManager.AppSettings [" CheckPassword"];的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的新项目中,他们使用了一个代码,例如

In my new project they have used one code like

string A = System.Configuration.ConfigurationManager.AppSettings["CheckPassword"];



这段代码有什么用?为什么使用这个?

这段代码有什么用呢?


What is the use of this code? why the are using this?
What could be the use of this code?

推荐答案

会有 web.config / app.config 该应用程序上存在的文件。检查一下。



那是 xml 文件通常包含应用程序的所有配置信息。



你会在父标签下的 AppSettings 标签内找到钥匙 CheckPassword 配置在该文件中如下所示。



There will be a web.config/app.config file existing on that application. Check that.

That is xml file usually contains all the configuartion information for the application.

You will find the key CheckPassword inside AppSettings tag under parent tag configuration inside that file something like below.

<configuration>
    <appSettings>
        <add key="CheckPassword" value="MyValue" />
    </appSettings>
</configuration>





我们以这种方式存储一些敏感信息避免在我们的应用程序中需要多次写入它。

如果需要更改,那么我们只需更改该配置文件,应用程序将完好无损。



因此,根据此层次结构,您将访问如下所示的值。



We store some sensitive information in this manner as to avoid writing it many times whenever needed inside our application.
And if it needs to be changed, then we just need to change at that configuration file and the application will work as intact.

So, according to this hierarchy, you will access that value like below.

string A = System.Configuration.ConfigurationManager.AppSettings["CheckPassword"];
// So, value of A will be "MyValue"







探索更多



1. appSettings元素(常规设置架构) [ ^ ]




Explore More

1. appSettings Element (General Settings Schema)[^]

Quote:

包含自定义应用程序设置,例如文件路径,XML Web服务URL或存储在其中的任何信息。应用程序的.ini文件。

Contains custom application settings, such as file paths, XML Web service URLs, or any information that is stored in the.ini file for an application.



2. ASP.NET appSettings [ ^ ]

3. ASP.NET配置文件层次结构和继承 [ ^ ]

4. ASP.NET配置文件 [ ^ ]


2. ASP.NET appSettings[^]
3. ASP.NET Configuration File Hierarchy and Inheritance[^]
4. ASP.NET Configuration Files[^]


我的部分答案

你将从web.config或app.config获得CheckPassword的值。
My Part of answer
You ll get the value of CheckPassword from web.config or app.config.


这个代码,您可以读取保存在web.config或app.config中的程序变量。

您可以从所有表单访问它。
With this code you can read the variables of your program that is saved in the web.config or app.config.
you can access to it from all forms.


这篇关于这段代码有什么用? System.Configuration.ConfigurationManager.AppSettings [&QUOT; CheckPassword&QUOT;];的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆