[web.config] 소스코드


</configSections> 

 

 

 

    <!-- 웹 사이트 전체에서 사용되는 상수 값 보관 -->

    <appSettings>

      <add key="SITE_NAME" value="닷넷코리아" />

      <add key="SITE_WIDTH" value="770" />

      <add key="SITE_MANAGER" value="구하라" />

    </appSettings>

 

 

 

    <!-- 데이터베이스 연결 문자열 -->

    <connectionStrings>

        <add

            name="ConnectionString"

            connectionString="server=.database=temp;uid=sa;pwd=Pa$$w0rd;"

            providerName="System.Data.SqlClient" />

    </connectionStrings>

 

 

    <system.web>





-------------------------------------------------------------------------------------



[Default.aspx] 소스코드 및 디자인



<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" 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></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>   

        사이트명 :

        <asp:Label ID="lblSITE_NAME" runat="server"></asp:Label>

        <br />

        Width :

        <asp:Label ID="lblSITE_WIDTH" runat="server"></asp:Label>

        <br />

        관리자 :

        <asp:Label ID="lblSITE_MANAGER" runat="server"></asp:Label>

        <br />

        <br />

        DB연결문자열 :

        <asp:Label ID="lblConnectionString" runat="server"></asp:Label>

        <br />

    </div>

    </form>

</body>

</html>

 










-------------------------------------------------------------------------------------




[Default.aspx.cs] 소스코드



using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Configuration;

using System.Web.Configuration;

 

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        // <appSettings /> 섹션을 읽어 오고 싶다...

        lblSITE_NAME.Text =

            System.Configuration.ConfigurationManager.AppSettings[0]; // ConfigurationManager는 윈도우 애플리케이션/웹 애플리케이션 둘 다 가능하다.

        lblSITE_WIDTH.Text =

            ConfigurationManager.AppSettings["SITE_WIDTH"].ToString();

        lblSITE_MANAGER.Text =

            System.Web.Configuration.WebConfigurationManager.AppSettings[2];  // WebConfigurationManager는 웹 애플리케이션 전용이다.

 

 

        // <connectionStrings /> 섹션

        lblConnectionString.Text =

            WebConfigurationManager.ConnectionStrings[

                "ConnectionString"].ConnectionString + "&nbsp;" +

                    WebConfigurationManager.ConnectionStrings[0].ProviderName;

    }

}

 

 

 

// global.asax 파일은 적용하려면 빌드를 해야 하지만, web.config 파일은 빌드하지 않고 동적으로 적용하기 때문에 더 빠르다.

// ConfigurationManager, WebConfigurationManager 둘 다 동일한 역할을 하지만 네임스페이스가 다르다.

 

 

 


-------------------------------------------------------------------------------------





[실행결과]






'.NET프로그래밍 > ASP.NET 3.5 SP1' 카테고리의 다른 글

SqlHelper 클래스와 Enterprise Library(4.1)  (0) 2009.10.21
WebDeployment (배포)  (0) 2009.10.21
WebOutputCache  (0) 2009.10.20
FrmQueryString  (0) 2009.10.20
FrmCookies  (0) 2009.10.20
Posted by holland14
: