Webconfigの値を取得@ASP.Net
Webconfigの値を取得します。
System.Configuration.ConfigurationManager.AppSettingsを利用します。
以下では、web.configのappSettingsにKEY「key1」で設定されている値を取得し、
ページロード時に、ラベルに値を表示しています。
●aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Webconfigの値を取得</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
|
●vb
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Label1.Text = System.Configuration.ConfigurationManager.AppSettings("key1")
End Sub
End Class
|
●web.config
<appSettings>
<add key="key1" value="key1値" />
</appSettings>
|