简体   繁体   English

从子网站web.config读取AppSettings

[英]Reading AppSettings From subsites web.config

I have aa subsite placed in my Default website. 我的默认网站上有一个子网站。 In the subsite I want to store variables in it's web.config. 在子站点中,我想将变量存储在web.config中。

However, whenever I try to retrieve the values, they don't exist in the ConfigurationManager.AppSettings. 但是,每当我尝试检索这些值时,它们在ConfigurationManager.AppSettings中都不存在。

I have put the website as a website application and created it as virtual directory in IIS, no success... 我已将该网站作为网站应用程序,并在IIS中将其创建为虚拟目录,但没有成功...

Does anyone have ane idea? 有人有想法吗?

Thanks! 谢谢!

(btw, I'm using .NET 3.5 and IIS Manager 6) (顺便说一句,我正在使用.NET 3.5和IIS Manager 6)

just FYI your subsites are called Virtual Diretories 仅供参考,您的子站点称为虚拟目录

in the web.config all you need to do is add this into the file: web.config您需要做的就是将其添加到文件中:

<configuration>
  <appSettings>
    <add key="myVar1" value="myValue1" />
    <add key="myVar2" value="myValue2" />
  </appSettings>
</configuration>

the <appSettings> is a simple NameValueCollection that you can itenerate in your code like: <appSettings>是一个简单的NameValueCollection ,您可以在代码中对其进行迭代,例如:

NameValueCollection appSettings = ConfigurationManager.AppSettings;

for (int i = 0; i < appSettings.Count; i++)
{
  Console.WriteLine("#{0} Key: {1} Value: {2}",
    i, appSettings.GetKey(i), appSettings[i]);
}

Is this what you are doing? 这是你在做什么吗?

Nevermind, 没关系,

I've fixed my own issue. 我已经解决了自己的问题。

I was using URL Rewrite which caused the server to get a bit confused about the actual location of my project. 我使用的是URL Rewrite,这使服务器对项目的实际位置有些困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM