In this article I will explain how to read or write appsettings in web.config file using asp.net.
In Previous article I explained clearly about how to read or write connectionstrings from web.config file in asp.net. Now I will explain how to write appsettings in web.config file and how to read appsettings from web.config file using asp.net.
<appSettings>
<add key="yourappsettingsstringName" value=" yourappsettingsvalue" />
</appSettings>
|
<appSettings>
<add key="dbconnection" value="Data
SOurce=SureshDasari;Initial Catalog=MysampleDB; Integrated Security=true"/>
</appSettings>
|
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Read or Write appsetting values from web.config file in
asp.net</title>
</head>
<body>
<form id="form1"
runat="server">
<div>
<asp:Label ID="lblText"
runat="server"/>
</div>
</form>
</body>
</html>
|
using System;
using
System.Configuration;
|
protected void
Page_Load(object sender, EventArgs e)
{
//Get appsettings string value
from web.config file
string strcon = ConfigurationManager.AppSettings["dbconnection"];
//Bind appsettings string value
to label
lblText.Text = strcon;
}
|
Imports System.Configuration
Partial Class
VBSample
Inherits System.Web.UI.Page
Protected Sub
Page_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.Load
'Get appsettings string value
from web.config file
Dim strcon As String = ConfigurationManager.AppSettings("dbconnection")
'Bind appsettings string value to
label
lblText.Text = strcon
End Sub
End Class
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
|
Subscribe by RSS
Subscribe by Email
1 comments :
I tried over and over times again, but I still can't write appsettings in web.config file. Where the problem is?