Is it correct to read from web.config file in the following way? i am using asp.net 2.0 VS 2005.I get the following error
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
anmar.SharpWebMail.UI.Login.Login_Click(... sender, EventArgs args) in login.cs:75
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.WebControls.
Application variables and web.config in asp.net 2.0?
To read a configuration setting from your web.config in VS 2005 use the following pattern:
string MyConfigValue = System.Configuration. ConfigurationManager. AppSettings["MyKey"];
That is if your setting is in the %26lt;appSettings%26gt; section of your web.config like this.
%26lt;appSettings%26gt;
%26lt;add key="Main.ConnectionString" value="data source=hydrogen.malinea.com;initial catalog=TeamC;User ID=usr_teamc;Password=TeamC;persist security info=False;packet size=4096;connection timeout=90;"/%26gt;
%26lt;/appSettings%26gt;
Hope this helps.
No comments:
Post a Comment