Can someone please explain to me what the deal is between using <applicationSettings> vs <appSettings> in the web.config?
This is what I know so far:
<applicationSettings> is a new method for storing app settings. It seems to be available to Window Forms Projects and Web Projects (but not Web Sites). This method provides strong names and intellisense. The settings are added by right clicking on the
Project in the solution explorer and selecting Properties and then the Settings Tab. (this doesn't seem to be available in a "Web Site" only a Web Project). Most of what I've read online shows this way of creating / configurating settings is for Windows Forms.....
This is the XML structure inside the web.config that is created on the settings tab:
My main problem with using this is I can't seem to use the above code in a class object. I get an error message telling me "Settings is not a Member of My". It does work fine from within an .aspx page. The really strange
part here is that if I remove the code and put a break point near where the code would be I can use the immediate window to execute the code and it will return the setting value...... I don't understand this at all.
The <appSettings> can be used in both Web Projects and Web Sites. You click "ASP.Configuration" under either the Project menu or the Web Site menu. A web based form pops up and allows you to create Application Settings. This seems to be the way people
are creating their App Settings for web apps.
However using this method does not give me strong names or intellisense. Which is the best method for creating app settings? Why? If I can use the first method how do I go about implementing the my.settings.myappsetting code in a class
object?
Thanks,
ASP.NET "Web Reference" "Web Application Projection" appSettingsVisual Studio 2005 SP1 Service Pack 1VS 2005asp.net 2.0Web Application Projectweb.config
Does anyone understand the difference between <applicationSettings> vs <appSettings>? Or has the 2005 development environment become so complex that best practices are no longer fully understood?
I will try to answer it specifically to your questions.
matchbx27
Can someone please explain to me what the deal is between using <applicationSettings> vs <appSettings> in the web.config?
ApplicationSettings are used in projects and is a newer constructs specifically from .net 2.0 onwards where as appSettings is a .net 1.1 construct. You can still use both of them.
configuration> <!-- other stuff not related to settings --> <applicationSettings> <SettingsDemo.My.MySettings> <setting name="AppBackColor" serializeAs="String"> <value>AntiqueWhite</value> </setting> </SettingsDemo.My.MySettings> </applicationSettings> </configuration>
Now that the new setting has been configured, it can be used in your code. In this case you could use it to initialize the background color of the main form. The setting is accessed using the My namespace (which is a major addition to Visual Basic 2005) and is much cleaner than our previous example.
Private Sub Form1_Load(...) Handles MyBase.Load Me.BackColor = My.Settings.AppBackColor End Sub
</div>
The <appSettings> can be used in both Web Projects and Web Sites. You click "ASP.Configuration" under either the Project menu or the Web Site menu. A web based form pops up and allows you to create Application Settings. This seems to be the way people
are creating their App Settings for web apps.
Which is the best method for creating app settings? Why? If I can use the first method how do I go about implementing the my.settings.myappsetting code in a class object?
Thanks,
Its entirely your choice, now you know the limitations and benefits. Look at the example I gave you and use it likewise, or let me know a particular problem.
Thanks for replying, but your post doesn't explain why I can't use my.settings.myvalue from within a class object. Also the msdn link you provided is for
Windows Forms Programming not Web Programming.
Can anyone confirm that <applicationSettings> is supposed to be available to Web Projects? Every site I visit for help in reguards to <applicationSettings> only shows it being used on Windows Forms Projects not on a Web Projec.
If you read the article, it tells that things are either declared in application scope or user scope, if you declare in userscope you can use it, otherwise its a read only. I do not know the setting of your application and hence cannot comment, if however
you create a sample for me..i can look into it.
Hope that helps
Further to your addition to post, If you read what I wrote..its available for projects whether web or windows but not as plain sites.
Please Mark Post that helped you as answer, also include a summary of what solved the problem as it helps others in similar situations
Can anyone point me to actual MSDN documentation concerning the use of <ApplicationSettings> with a Web Project?
I am highly skeptical that MS indends <applicationSettings> to be used in a Web Project (at least at this point in time) and more inclined to believe that this is something that accidentally happened when Microsoft released the patch that allowed users to
once again create Web Projects in Visual Studio (it was a patch for awhile but is now rolled into SP1).
The reason for this skepticism..... just do a google search
google "my Namespace" "Web Projects" I get 118 results.
google "my Namespace" "Windows Forms" I get 11,400 results.
Thanks for the links you provided naturehermit, but they don't provide a definitive answer toward the use of <applicationSettings> in a Web Project. And here's why:
The word web only shows up once in the MSDN article:
I will be implementing the old style <appSettings>. Mainly due the fact that no one can point me to any documentation that explains speific use of <applicationSettings> in a Web Project.
matchbx27
Contributor
3432 Points
699 Posts
<applicationSettings> vs <appSettings>
Jun 20, 2007 02:01 PM|LINK
Can someone please explain to me what the deal is between using <applicationSettings> vs <appSettings> in the web.config?
This is what I know so far:
<applicationSettings> is a new method for storing app settings. It seems to be available to Window Forms Projects and Web Projects (but not Web Sites). This method provides strong names and intellisense. The settings are added by right clicking on the Project in the solution explorer and selecting Properties and then the Settings Tab. (this doesn't seem to be available in a "Web Site" only a Web Project). Most of what I've read online shows this way of creating / configurating settings is for Windows Forms.....
This is the XML structure inside the web.config that is created on the settings tab:
<applicationSettings>
<ProjectName.My.MySettings>
<setting name="myappsetting" serializeAs="String"><value>myvalue</value>
</setting>
</ProjectName.My.MySettings>
</applicationSettings>
This is how you access it in code:
My
.Settings.myappsettingMy main problem with using this is I can't seem to use the above code in a class object. I get an error message telling me "Settings is not a Member of My". It does work fine from within an .aspx page. The really strange part here is that if I remove the code and put a break point near where the code would be I can use the immediate window to execute the code and it will return the setting value...... I don't understand this at all.
The <appSettings> can be used in both Web Projects and Web Sites. You click "ASP.Configuration" under either the Project menu or the Web Site menu. A web based form pops up and allows you to create Application Settings. This seems to be the way people are creating their App Settings for web apps.
Here is the structure of the Web.Config:
<
appSettings><add key="myappsetting" value="myvalue" />
</appSettings>
However using this method does not give me strong names or intellisense. Which is the best method for creating app settings? Why? If I can use the first method how do I go about implementing the my.settings.myappsetting code in a class object?
Thanks,
ASP.NET "Web Reference" "Web Application Projection" appSettings Visual Studio 2005 SP1 Service Pack 1 VS 2005 asp.net 2.0 Web Application Project web.config
matchbx27
Contributor
3432 Points
699 Posts
Re: <applicationSettings> vs <appSettings>
Jun 21, 2007 12:52 PM|LINK
Does anyone understand the difference between <applicationSettings> vs <appSettings>? Or has the 2005 development environment become so complex that best practices are no longer fully understood?
naturehermit
Star
14610 Points
3046 Posts
Re: <applicationSettings> vs <appSettings>
Jun 21, 2007 02:31 PM|LINK
I will try to answer it specifically to your questions.
ApplicationSettings are used in projects and is a newer constructs specifically from .net 2.0 onwards where as appSettings is a .net 1.1 construct. You can still use both of them.
<div class=MsoNormal><appSettings> <add key="ConnString" value="server=(local);database=pubs;uid=;pwd=;"/> </appSettings></div>Settings could be retrieved as such: However it doesnt give you intellisense.
<div class=MsoNormal>MyConnectionString = ConfigurationSettings.AppSettings("ConnString")and forconfiguration><!-- other stuff not related to settings -->
<applicationSettings>
<SettingsDemo.My.MySettings>
<setting name="AppBackColor" serializeAs="String">
<value>AntiqueWhite</value>
</setting>
</SettingsDemo.My.MySettings>
</applicationSettings>
</configuration>
</div>The <appSettings> can be used in both Web Projects and Web Sites. You click "ASP.Configuration" under either the Project menu or the Web Site menu. A web based form pops up and allows you to create Application Settings. This seems to be the way people are creating their App Settings for web apps.
Here is the structure of the Web.Config:
<
appSettings><add key="myappsetting" value="myvalue" />
</appSettings>
Gives you intellisense
Its entirely your choice, now you know the limitations and benefits. Look at the example I gave you and use it likewise, or let me know a particular problem.
For your reference.
http://msdn2.microsoft.com/en-us/library/k4s6c3a0(VS.80).aspx
http://msmvps.com/blogs/windsor/archive/2007/01.aspx
matchbx27
Contributor
3432 Points
699 Posts
Re: <applicationSettings> vs <appSettings>
Jun 21, 2007 06:06 PM|LINK
Thanks for replying, but your post doesn't explain why I can't use my.settings.myvalue from within a class object. Also the msdn link you provided is for Windows Forms Programming not Web Programming.
Can anyone confirm that <applicationSettings> is supposed to be available to Web Projects? Every site I visit for help in reguards to <applicationSettings> only shows it being used on Windows Forms Projects not on a Web Projec.
naturehermit
Star
14610 Points
3046 Posts
Re: <applicationSettings> vs <appSettings>
Jun 21, 2007 06:08 PM|LINK
If you read the article, it tells that things are either declared in application scope or user scope, if you declare in userscope you can use it, otherwise its a read only. I do not know the setting of your application and hence cannot comment, if however you create a sample for me..i can look into it.
Hope that helps
Further to your addition to post, If you read what I wrote..its available for projects whether web or windows but not as plain sites.
matchbx27
Contributor
3432 Points
699 Posts
Re: <applicationSettings> vs <appSettings>
Jun 21, 2007 06:11 PM|LINK
In a Web Project the only item available in the Scope Dropdown box is "Application". No other options are available.
matchbx27
Contributor
3432 Points
699 Posts
Re: <applicationSettings> vs <appSettings>
Jun 22, 2007 12:14 PM|LINK
Can anyone point me to actual MSDN documentation concerning the use of <ApplicationSettings> with a Web Project?
I am highly skeptical that MS indends <applicationSettings> to be used in a Web Project (at least at this point in time) and more inclined to believe that this is something that accidentally happened when Microsoft released the patch that allowed users to once again create Web Projects in Visual Studio (it was a patch for awhile but is now rolled into SP1).
The reason for this skepticism..... just do a google search
google "my Namespace" "Web Projects" I get 118 results.
google "my Namespace" "Windows Forms" I get 11,400 results.
Thanks for the links you provided naturehermit, but they don't provide a definitive answer toward the use of <applicationSettings> in a Web Project. And here's why:
The word web only shows up once in the MSDN article:
"Your Windows Forms applications will often require data that is critical to running the application, but which you do not want to include directly in the application's code. If your application uses a Web Service or a database server, you may want to store this information in a separate file, so that you can change it in the future without re-compiling."
and only once in the weblog:
Most applications require some configuration settings that could change over time. Classic examples would be a connection string to a database, the URL to your company web site, or the path to a log file.
matchbx27
Contributor
3432 Points
699 Posts
Re: <applicationSettings> vs <appSettings>
Jun 25, 2007 04:13 PM|LINK
I will be implementing the old style <appSettings>. Mainly due the fact that no one can point me to any documentation that explains speific use of <applicationSettings> in a Web Project.
Thanks,
matchbx