본문 바로가기

프로그래밍언어/ASP.NET

프로필(profiles)

프로필: 웹 응용 프로그램의 개인 설정을 위해 사용자 설정 정보를 저장하고 관리해주는 asp.net 의 기능

프로필 속성 선언

<profile>

<properties>

<add name="mainbackcolor" />

<add name="enablecalendar" type="System.Boolean" />

<group name="meminfos">

<add name="nickname" />

<add name="age" type="System.int32" />

</group>

</properties>

</profile>

 

// 사용자 설정 정보 입력

Profile.mainbackcolor = "red";

Profile.enablecalendar = true;

Profile.meminfos.nickname = "동네 노는 청년";

Profile.meminfos.age = 2;

 

// 사용자 설정 정보 참조

String mainbackcolor = Profile.mainbackcolor;

Bool enablecalender = Profile.enablecalendar;

String nickname = Profile.meminfos.nickname;

Int age = Profile.meminfos.age;

 

인증된 사용자를 위한 프로필

Web.config

<?xml version="1.0"?>

<configuration>

    <configSections>

        <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

            <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

                <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

                <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

                    <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>

                    <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

                    <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

                    <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

                </sectionGroup>

            </sectionGroup>

        </sectionGroup>

    </configSections>

    <connectionStrings>

        <add name="MyLocalSqlServer" connectionString="Data Source=.;Initial Catalog=aspnetdb;User ID=sa;Password=rlathwjd.1" providerName="System.Data.SqlClient"/>

    </connectionStrings>

    <system.web>

        <compilation debug="true">

            <assemblies>

                <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

                <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

                <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

                <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

            </assemblies>

        </compilation>

        <authentication mode="Forms">

            <forms loginUrl="Login.aspx" defaultUrl="Home.aspx"></forms>

        </authentication>

        <membership defaultProvider="MyAspNetSqlMembershipProvider">

            <providers>

                <add name="MyAspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="MyLocalSqlServer" requiresQuestionAndAnswer="false" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0"/>

            </providers>

        </membership>

        <!--

<anonymousIdentification enabled="true"/>

-->

        <profile defaultProvider="MyAspNetSqlProfileProvider">

            <providers>

                <add name="MyAspNetSqlProfileProvider" connectionStringName="MyLocalSqlServer" type="System.Web.Profile.SqlProfileProvider"/>

            </providers>

            <properties>

                <add name="MainBackColor"/>

                <add name="EnableCalendar" type="System.Boolean"/>

            </properties>

        </profile>

        <pages>

            <controls>

                <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

                <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

            </controls>

        </pages>

        <httpHandlers>

            <remove verb="*" path="*.asmx"/>

            <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

            <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

            <add verb="GET,HEAD" path="ScriptResource.axd" validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

        </httpHandlers>

        <httpModules>

            <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

        </httpModules>

    </system.web>

    <location path="secured">

        <system.web>

            <authorization>

                <deny users="?"/>

                <allow users="*"/>

            </authorization>

        </system.web>

    </location>

    <system.codedom>

        <compilers>

            <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">

                <providerOption name="CompilerVersion" value="v3.5"/>

                <providerOption name="WarnAsError" value="false"/>

            </compiler>

            <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">

                <providerOption name="CompilerVersion" value="v3.5"/>

                <providerOption name="OptionInfer" value="true"/>

                <providerOption name="WarnAsError" value="false"/>

            </compiler>

        </compilers>

    </system.codedom>

    <system.webServer>

        <validation validateIntegratedModeConfiguration="false"/>

        <modules>

            <remove name="ScriptModule"/>

            <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

        </modules>

        <handlers>

            <remove name="WebServiceHandlerFactory-Integrated"/>

            <remove name="ScriptHandlerFactory"/>

            <remove name="ScriptHandlerFactoryAppServices"/>

            <remove name="ScriptResource"/>

            <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

            <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

            <add name="ScriptResource" verb="GET,HEAD" path="ScriptResource.axd" preCondition="integratedMode" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

        </handlers>

    </system.webServer>

    <runtime>

        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

            <dependentAssembly>

                <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>

                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>

            </dependentAssembly>

            <dependentAssembly>

                <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>

                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>

            </dependentAssembly>

        </assemblyBinding>

    

    </runtime>

      

    

</configuration>

 

 

Masterpage.master

<%@ Master Language="C#" %>

 

<!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>

<table cellspacing="0" cellpadding="5" border="1" width="500" style="height:80%;">

<tr style="height:20px">

<td style="width:200px;">

<h3>Web Site Logo</h3>

</td>

<td style="width:300px;">

<table width="100%">

<tr>

<td><b>Top Menu</b></td>

<td align="right">

<asp:LoginStatus ID="loginstatus" runat="server" />

</td>

</tr>

</table>

 

</td>

</tr>

 

<tr>

<td valign="top">

<asp:LoginView ID="LoginView1" runat="server">

<LoggedInTemplate>

<asp:LoginName ID="LoginName1" runat="server" FormatString="{0} 님 반갑습니다!!" />

 

</LoggedInTemplate>

<AnonymousTemplate>

<asp:Login ID="Login1" runat="server" CreateUserUrl="~/CreateUser.aspx" CreateUserText="회원가입" BackColor="Beige" BorderColor="ButtonHighlight" BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="Crimson" TextLayout="TextOnTop">

<TitleTextStyle BackColor="DarkSlateBlue" Font-Bold="true" Font-Size="0.9em" ForeColor="White" />

<InstructionTextStyle Font-Italic="true" ForeColor="Black" />

<TextBoxStyle Font-Size="0.8em" />

<LoginButtonStyle BackColor="White" BorderColor="DarkMagenta" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="PapayaWhip" />

</asp:Login>

</AnonymousTemplate>

 

</asp:LoginView>

<p></p>

<b>Left Menu</b>

</td>

<td valign="top" style="height:250px; ">

<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

</asp:ContentPlaceHolder>

</td>

</tr>

<tr>

<td colspan="2" ><b> Bottom Menu</b></td>

</tr>

</table>

</div>

</form>

</body>

</html>

 

Login.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" %>

 

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<asp:Login ID="Login1" runat="server"></asp:Login>

</asp:Content>

Createuser.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" %>

 

 

 

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" ContinueDestinationPageUrl="~/Home.aspx" >

<WizardSteps>

<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">

</asp:CreateUserWizardStep>

<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">

</asp:CompleteWizardStep>

</WizardSteps>

 

</asp:CreateUserWizard>

 

</asp:Content>

 

Home.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="제목 없음" %>

 

<script runat="server">

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

StyleContainer.Style.Add(HtmlTextWriterStyle.BackgroundColor, Profile.MainBackColor);

Calendar1.Visible = Profile.EnableCalendar;

}

}

protected void Button1_Click(object sender, EventArgs e)

{

Response.Redirect("SelfProfile.aspx");

}

 

</script>

 

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<div id="StyleContainer" runat="server">

메인페이지입니당<p></p>

<asp:Calendar ID="Calendar1" runat="server" ></asp:Calendar>

<p></p>

<asp:Button ID="button1" runat="server" Text="사용자 설정 페이지로 이동" OnClick="Button1_Click" />

</div>

 

</asp:Content>

 

Selfprofile.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" %>

 

<script runat="server">

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

ListItem i1 = DropDownList1.Items.FindByValue(Profile.MainBackColor);

if (i1 != null)

i1.Selected = true;

if (Profile.EnableCalendar)//캘린더를 사용한다면

RadioButton1.Checked = true;

else //캘린더를 사용하지 않는다면

RadioButton1.Checked = true;

}

}

 

protected void Button1_Click(object sender, EventArgs e)

{

Profile.MainBackColor = DropDownList1.SelectedItem.Value;

if (RadioButton1.Checked)

Profile.EnableCalendar = true; //캘린더 사용

else

Profile.EnableCalendar = false; // 캘린더 미사용

}

protected void Button2_Click(object sender, EventArgs e)

{

Response.Redirect("~/Home.aspx");

}

 

 

 

</script>

 

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

메인 페이지 배경 색상:

<asp:DropDownList ID="DropDownList1" runat="server">

<asp:ListItem Value="">기본</asp:ListItem>

<asp:ListItem Value="red" >Red</asp:ListItem>

<asp:ListItem Value="green" >Green</asp:ListItem>

<asp:ListItem Value="blue" >Blue</asp:ListItem>

</asp:DropDownList><br />

캘린더 사용 여부:

<asp:RadioButton ID="RadioButton1" runat="server" Text="사용" GroupName="CheckCalender" Checked="true" />

<asp:RadioButton ID="RadioButton2" runat="server" Text="미사용" GroupName="CheckCalender" Checked="true" />

<asp:Button ID="Button1" runat="server" Text="설정 상태 저장" OnClick="Button1_Click" />

<asp:Button ID="Button2" runat="server" Text="메인 페이지....." OnClick="Button2_Click" />

 

 

</asp:Content>

 

익명 사용자를 위한 프로필

Web.config

<anonymousIdentification enabled="true"/>

        <profile defaultProvider="MyAspNetSqlProfileProvider">

            <providers>

                <add name="MyAspNetSqlProfileProvider" connectionStringName="MyLocalSqlServer" type="System.Web.Profile.SqlProfileProvider" />

            </providers>

            <properties>

                <add name="MainBackColor" allowAnonymous="true"/>

                <add name="EnableCalendar" type="System.Boolean" allowAnonymous="true" />

            </properties>

        </profile>

프로필 이동(익명사용자 -> 인증된 사용자)

익명사용자가 설정한 사용자 설정 정보는 익명 사용자가 로그인한 직후 인증된 사용자가 되었을 때 인증된 사용자의 사용자 설정 정보로 이동될 수 있음

Global.asax

<%@ Application Language="C#" %>

 

<script runat="server">

 

void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs e)

{

//익명 사용자 프로필을 가져온다

ProfileCommon anonProfile = Profile.GetProfile(e.AnonymousID);

 

//익명 사용자 프로필을 인증된 사용자 프로필에 저장한다

Profile.MainBackColor = anonProfile.MainBackColor;

Profile.EnableCalendar = anonProfile.EnableCalendar;

 

//익명 사용자 프로필 및 익명 사용자 ID를 삭제한다

 

ProfileManager.DeleteProfile(e.AnonymousID);

AnonymousIdentificationModule.ClearAnonymousIdentifier();

}

 

</script>

 

15장 웹 파트(web parts)

웹 파트: 페이지에 포함된 각 콘텐츠를 모듈화 하는 데 사용되는 통합 컨트롤 집합

웹 페이지의 한 부분을 구현하기 위해 제공되는 기능

 

웹 파트 영역(web part zone)

<asp:WebPartZone ID="WebPartZone1" runat="server">

</asp:WebPartZone>

Web.config

<?xml version="1.0"?>

<configuration>

    <appSettings/>

    <connectionStrings/>

    <system.web>

        <compilation debug="true"/>

        <authentication mode="Forms">

            <forms loginUrl="Login.aspx" defaultUrl="Home.aspx"></forms>

        </authentication>

    

    </system.web>

</configuration>

 

Masterpage.master

<%@ Master Language="C#" %>

 

<!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>

<table cellspacing="0" cellpadding="5" border="1" width="500" style="height:80%;">

<tr style="height:20px">

<td style="width:200px;">

<h3>Web Site Logo</h3>

</td>

<td style="width:300px;">

<table width="100%">

<tr>

<td><b>Top Menu</b></td>

<td align="right">

<asp:LoginStatus ID="loginstatus" runat="server" />

</td>

</tr>

</table>

 

</td>

</tr>

 

<tr>

<td valign="top">

<asp:LoginView ID="LoginView1" runat="server">

<LoggedInTemplate>

<asp:LoginName ID="LoginName1" runat="server" FormatString="{0} 님 반갑습니다!!" />

 

</LoggedInTemplate>

<AnonymousTemplate>

<asp:Login ID="Login1" runat="server" CreateUserUrl="~/CreateUser.aspx" CreateUserText="회원가입" BackColor="Beige" BorderColor="ButtonHighlight" BorderPadding="4" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="Crimson" TextLayout="TextOnTop">

<TitleTextStyle BackColor="DarkSlateBlue" Font-Bold="true" Font-Size="0.9em" ForeColor="White" />

<InstructionTextStyle Font-Italic="true" ForeColor="Black" />

<TextBoxStyle Font-Size="0.8em" />

<LoginButtonStyle BackColor="White" BorderColor="DarkMagenta" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="PapayaWhip" />

</asp:Login>

</AnonymousTemplate>

 

</asp:LoginView>

<p></p>

<b>Left Menu</b>

</td>

<td valign="top" style="height:250px; ">

<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

</asp:ContentPlaceHolder>

</td>

</tr>

<tr>

<td colspan="2" ><b> Bottom Menu</b></td>

</tr>

</table>

</div>

</form>

</body>

</html>

 

Createuser.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" %>

 

 

 

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" ContinueDestinationPageUrl="~/Home.aspx" >

<WizardSteps>

<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">

</asp:CreateUserWizardStep>

<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">

</asp:CompleteWizardStep>

</WizardSteps>

 

</asp:CreateUserWizard>

 

</asp:Content>

 

Login.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" %>

 

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<asp:Login ID="Login1" runat="server"></asp:Login>

</asp:Content>

 

Webusercontrol1.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl1.ascx.cs" Inherits="WebUserControl1" %>

 

검색:<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>

<asp:Button ID="Button1" runat="server" Text="바튼" />

 

Home.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" %>

<%@ Register Src="~/WebUserControl1.ascx" TagName="WebUserControl1" TagPrefix="uc1" %>

 

 

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<asp:WebPartManager ID="WebPartManager1" runat="server"></asp:WebPartManager>

<table width="100%">

<tr>

<td valign="top">

<asp:WebPartZone ID="WebPartZone1" runat="server">

<ZoneTemplate>

<asp:Panel ID="Panel1" runat="server" Height="50px" Width="120px" title="공지사항">

*3월 세미나에서 여러분을...<br />

*2월 세미나에서 여러분을...</asp:Panel>

</ZoneTemplate>

</asp:WebPartZone>

</td>

 

<td valign="top">

<asp:WebPartZone ID="WebPartZone2" runat="server">

<ZoneTemplate>

<uc1:WebUserControl1 ID="WebUserControl1_1" runat="server" title="사이트 검색" />

</ZoneTemplate>

</asp:WebPartZone>

</td>

 

<td valign="top"></td>

</tr>

<tr>

<td valign="top">

<asp:WebPartZone ID="WebPartZone3" runat="server" >

<ZoneTemplate>

<asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px" title="오늘의 뉴스">

* 국산 지상파 DMB폰 중국 가나?<br />

* 화장지 길이 속여 수억 이득 봣나?</asp:Panel>

</ZoneTemplate>

</asp:WebPartZone>

</td>

 

<td valign="top">

<asp:WebPartZone ID="WebPartZone4" runat="server">

<ZoneTemplate>

<asp:Calendar ID="Calendar1" runat="server" title="세미나 일정" ></asp:Calendar>

</ZoneTemplate>

</asp:WebPartZone>

</td>

<td valign="top"></td>

</tr>

 

</table>

</asp:Content>

 

웹 파트 이동하기

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" %>

<%@ Register Src="~/WebUserControl1.ascx" TagName="WebUserControl1" TagPrefix="uc1" %>

 

<script runat="server">

protected void Page_Init(object sender, EventArgs e)

{

foreach (WebPartDisplayMode mode in WebPartManager1.SupportedDisplayModes)

{

string modeName = mode.Name;

if (mode.IsEnabled(WebPartManager1))

{

ListItem li = new ListItem(modeName, modeName);

DropDownList1.Items.Add(li);

}

}

}

 

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

{

string selectedMode = DropDownList1.SelectedValue;

WebPartDisplayMode mode = WebPartManager1.SupportedDisplayModes[selectedMode];

if (mode != null)

WebPartManager1.DisplayMode = mode;

}

</script>

 

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<asp:WebPartManager ID="WebPartManager1" runat="server"></asp:WebPartManager>

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>

<table width="100%">

<tr>

<td valign="top">

<asp:WebPartZone ID="WebPartZone1" runat="server">

<ZoneTemplate>

<asp:Panel ID="Panel1" runat="server" Height="50px" Width="120px" title="공지사항">

*3월 세미나에서 여러분을...<br />

*2월 세미나에서 여러분을...</asp:Panel>

</ZoneTemplate>

</asp:WebPartZone>

</td>

 

<td valign="top">

<asp:WebPartZone ID="WebPartZone2" runat="server">

<ZoneTemplate>

<uc1:WebUserControl1 ID="WebUserControl1_1" runat="server" title="사이트 검색" />

</ZoneTemplate>

</asp:WebPartZone>

</td>

 

<td valign="top"></td>

</tr>

<tr>

<td valign="top">

<asp:WebPartZone ID="WebPartZone3" runat="server" >

<ZoneTemplate>

<asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px" title="오늘의 뉴스">

* 국산 지상파 DMB폰 중국 가나?<br />

* 화장지 길이 속여 수억 이득 봣나?</asp:Panel>

</ZoneTemplate>

</asp:WebPartZone>

</td>

 

<td valign="top">

<asp:WebPartZone ID="WebPartZone4" runat="server">

<ZoneTemplate>

<asp:Calendar ID="Calendar1" runat="server" title="세미나 일정" ></asp:Calendar>

</ZoneTemplate>

</asp:WebPartZone>

</td>

<td valign="top"></td>

</tr>

 

</table>

</asp:Content>

 

 

카탈로그 영역(catalog zone)

페이지 카탈로그 파트

<td valign="top">

<asp:CatalogZone ID="Catalogzone1" runat="server" >

<ZoneTemplate>

<asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />

</ZoneTemplate>

</asp:CatalogZone>

</td>

 

선언적 카탈로그 파트

<td valign="top">

<asp:CatalogZone ID="Catalogzone1" runat="server" >

<ZoneTemplate>

<asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />

<asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server">

<WebPartsTemplate>

<asp:FileUpload ID="FileUpload1" runat="server" title="선언된 웨 파트1" />

</WebPartsTemplate>

</asp:DeclarativeCatalogPart>

</ZoneTemplate>

</asp:CatalogZone>

</td>

가져온 웹 파트 카탈로그 파트

<td valign="top">

<asp:CatalogZone ID="Catalogzone1" runat="server" >

<ZoneTemplate>

<asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />

<asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server">

<WebPartsTemplate>

<asp:FileUpload ID="FileUpload1" runat="server" title="선언된 웨 파트1" />

</WebPartsTemplate>

</asp:DeclarativeCatalogPart>

<asp:ImportCatalogPart ID="ImportCatalogPart1" runat="server" />

</ZoneTemplate>

</asp:CatalogZone>

</td>

 

편집기 영역(editor zone)

모양 편집기 파트와 레이아웃 편집기 파트

<td valign="top">

<asp:EditorZone ID="EditorZone1" runat="server">

<ZoneTemplate>

<asp:AppearanceEditorPart ID="AppearanceEditorPart1" runat="server" />

<asp:LayoutEditorPart ID="LayoutEditorPart1" runat="server" />

</ZoneTemplate>

</asp:EditorZone>

</td>

 

동작 편집기 파트

<system.web>

        <webParts enableExport="true">

            <personalization>

                <authorization>

                    <allow verbs="enterSharedScope" users="user1"/>

                </authorization>

            </personalization>

 

        </webParts>

 

    </system.web>

 

<td valign="top">

<asp:EditorZone ID="EditorZone1" runat="server">

<ZoneTemplate>

<asp:AppearanceEditorPart ID="AppearanceEditorPart1" runat="server" />

<asp:LayoutEditorPart ID="LayoutEditorPart1" runat="server" />

<asp:BehaviorEditorPart ID="BehaviorEditorPart1" runat="server" />

</ZoneTemplate>

</asp:EditorZone>

</td>

 

 

protected void Page_Load(object sender, EventArgs e)

{

if (WebPartManager1.Personalization.Scope == PersonalizationScope.User && WebPartManager1.Personalization.CanEnterSharedScope)

{

WebPartManager1.Personalization.ToggleScope();

}

 

Label1.Text = WebPartManager1.Personalization.Scope.ToString();

}

 출처: 뇌를 자극하는 asp.net 2.0