asp.net Web.Config常用

來源:互聯網
上載者:User

標籤:io   ar   strong   檔案   資料   sp   cti   log   on   

Web.config檔案是一個xml文字檔,它的根節點為<configuration>,該節點下包含常見的子節點有:<configSections>、<appSettings>、<connectionStrings>(儲存資料庫連接字串)、<location>和<system.web>。

 

<appSettings>

該節點下主要用來儲存asp.net應用程式的一些配置資訊,也可以把資料庫連接字串也放在這裡,不過.net2.0提供了connectionStrings節點,所以資料庫連接字串還是不建議放在這裡,下面為一個圖片類型的執行個體。

<appSettings>

<!--圖片類型副檔名-->

<add key="ImgType" value=".bmp;.jpg;.gif;.png"/>

</appSettings>

調用方法為:

string ImgType = ConfigurationManager.AppSettings["ImgType"]

 

<connectionStrings>

 

connectionStrings和appSettings類似,不過用於儲存設定資料庫串連資訊,下面給一個執行個體。

<connectionStrings>

<add name="SqlserverConnStr" connectionString="Data Source=Aron1;Initial Catalog= pubs;UserId=sa;Password=asdasd;"/>

<add name="OrcleConnStr" connectionString="Provider=msdaora;Data Source= MyOracleDB;UserId=UserName;Password=asdasd;"/>

</connectionStrings>

調用方式為:

引用命名空間:using System.Configuration;

string connStr = ConfigurationManager.ConnectionStrings["SqlserverConnStr"].ConnectionString;

asp.net Web.Config常用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.