appSettings and ConfigurationManager.AppSettings issue

后端 未结 8 1563
情书的邮戳
情书的邮戳 2021-02-12 22:36

I have searched the site, and while I found some very useful information, I couldn\'t figure out what is going on with my code. I have the following web.config:



        
相关标签:
8条回答
  • 2021-02-12 23:25

    I bet u r using the right syntax to access them when you write: ConfigurationManager.AppSettings["Key1"];

    Try this format for the web config

    <?xml version="1.0"?>
    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    <appSettings>
        <add key="Key1" value="Val1"/>
        <add key="Key2" value="Val2"/>
    </appSettings>
    <connectionStrings>
        ......
        ......
    </connectionStrings>
    <system.web>
        <sessionState mode="InProc" timeout="20"/>
        <authorization>
            ......
        </authorization>
    
        <pages>
            <namespaces>
                <add namespace="System.Data"/>
                <add namespace="System.Data.SqlClient"/>
                <add namespace="System.IO"/>
            </namespaces>
        </pages>
        <customErrors mode="Off"/>
        <compilation debug="true"/></system.web>
    </configuration>
    
    0 讨论(0)
  • 2021-02-12 23:39

    i have two project in my solution first i add app.config file in class library project which all instances is call from console application i added these entries in config file in class lib project

    <appSettings> 
    <add key="userName" value="user2" /> 
    <add key="emilsLimit" value="50" /> 
    </appSettings>
    

    it was throwing null exception when i get these in a class in class library project but when i delete app.config from class Library project and added in Console project it works.Cheers

    Note: Class lib project reference is added in console

    0 讨论(0)
提交回复
热议问题