1

I am facing an issue with getting a value from Web.config.

Here is my web.config code which contains Key

<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="Email" value="myname@mydomain.com" />

i want email key value, i am writing,

  string From = ConfigurationManager.AppSettings["Email"].ToString();

but its giving me error "Object reference is not set to an instance of an object"

My other web.config declarations are:

<system.net>
    <mailSettings>
        <smtp>
            <network host="smtp.gmail.com" port="***" enableSsl="true" defaultCredentials="false" userName="myname@mydomain.com" password="mypassword" />
        </smtp>
    </mailSettings>
</system.net>

Any help appreciated! Thanks!

4

1 回答 1

1

确保您的启动项目设置正确。如果您从一个单独的项目(即在测试中)运行它,它不会查看该 Web.config,而是查看它自己的 Web/App.config 文件。

于 2013-04-04T15:20:33.497 回答