gpt4 book ai didi

c# - 在 ASP.net 中进行设置的最佳方式

转载 作者:太空宇宙 更新时间:2023-11-03 22:15:54 26 4
gpt4 key购买 nike

通过设置,我总是在某处的文件中有一些 const 变量。是否可以使用我网站的所有设置创建一个新的配置文件?即:

CONST imagePrefixPath = "http://img.domain.com/"

是那种我想在整个网络代码中存储和使用的东西

最佳答案

改用 web.config 中的 appSettings:

<configuration>
<appSettings>
<add key="imagePrefixPath" value="http://img.domain.com/" />
</appSettings>
</configuration>

然后在代码中访问它使用 appSettings 访问 OpenWebConfiguration 变量

System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);
String imagePath = config.AppSettings.Settings["imagePrefixPath"] + "myimage.jpg";

关于c# - 在 ASP.net 中进行设置的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5207053/

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