「web.configの設定記述を、外部ファイルに定義し、プログラム部分から取得する」の編集履歴(バックアップ)一覧に戻る
web.configの設定記述を、外部ファイルに定義し、プログラム部分から取得する - (2008/01/21 (月) 15:23:16) のソース
*web.configの設定記述を、外部ファイルに定義し、プログラム部分から取得する ***概要 1.web.configの設定記述を、外部ファイルに定義する。 2.プログラム部分から1を取得する。 ***前提条件 -[[新しいwebサイトの作成]] ***手順 custom.configというファイル名で以下を追加する。 #highlight(xml){{ <?xml version="1.0" encoding="UTF-8" ?> <appSettings> <add key="ConnectString" value="Provider=SQLOLEDB;Persist Security Info=True; Password=sa;User ID=sa;Initial Catalog=netinsider;Data Source=(local)" /> </appSettings> }} web.config中の「appSettings」に「file」を指定 #highlight(xml){{ <appSettings file="custom.config"/> }} default.aspx.vbで以下のように取得 #highlight(vb.net){{ Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Response.Write(System.Configuration.ConfigurationManager.AppSettings("ConnectString")) End Sub End Class }} 実行すると以下のような感じ。 #img(114.jpg)