开发者

Reading AppSettings From subsites web.config

I have a a subsite placed in my Default website. In the subsite I want to store开发者_Python百科 variables in it's web.config.

However, whenever I try to retrieve the values, they don't exist in the ConfigurationManager.AppSettings.

I have put the website as a website application and created it as virtual directory in IIS, no success...

Does anyone have ane idea?

Thanks!

(btw, I'm using .NET 3.5 and 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:

<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:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜