ProfileBase 클래스

정의

프로필 속성 값과 정보에 대한 형식화되지 않은 액세스를 제공합니다.

public ref class ProfileBase : System::Configuration::SettingsBase
public class ProfileBase : System.Configuration.SettingsBase
type ProfileBase = class
    inherit SettingsBase
Public Class ProfileBase
Inherits SettingsBase
상속
ProfileBase
파생

예제

다음 코드 예제에서는 형식의 속성과 RecentSearchList 형식 string StringCollection의 속성을 포함하는 ZipCode 사용자 프로필을 지정하는 Web.config 파일을 보여 줍니다. 현재 HttpContext 생성된 Profile 속성에는 지정된 각 속성에 대해 강력한 형식의 접근자가 있습니다.

<configuration>
  <system.web>
    <anonymousIdentification enabled="true" />

    <profile enabled="true" defaultProvider="SqlProvider" >
      <properties>
        <add name="ZipCode" allowAnonymous="true" />
        <add name="RecentSearchList"
          type="System.Collections.Specialized.StringCollection"
          serializeAs="Xml"
          allowAnonymous="true" />
      </properties>
    </profile>
  </system.web>
</configuration>

다음 예제에서는 사용자 프로필에 대해 지정된 속성을 읽고 설정하는 ZipCode ASP.NET 페이지를 보여줍니다. 이 코드를 실행하기 전에 웹 사이트의 ASP.NET 구성 설정에서 공급자를 기본값 AspNetSqlProvider 으로 설정합니다.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

public void Page_PreRender()
{
  if (Profile.ZipCode == null)
  {
    PersonalizePanel.Visible = false;
    GetZipCodePanel.Visible = true;
  }
  else
  {
    ZipCodeLabel.Text = Profile.ZipCode;

    // Get personalized information for zip code here.

    PersonalizePanel.Visible = true;
    GetZipCodePanel.Visible = false;
  }
}

public void ChangeZipCode_OnClick(object sender, EventArgs args)
{
  ZipCodeTextBox.Text = Profile.ZipCode;
  Profile.ZipCode = null;

  PersonalizePanel.Visible = false;
  GetZipCodePanel.Visible = true;
}

public void EnterZipCode_OnClick(object sender, EventArgs args)
{
  Profile.ZipCode = ZipCodeTextBox.Text;
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Home Page</title>
</head>
<body>

<form id="form1" runat="server">
  <table border="1" cellpadding="2" cellspacing="2">
    <tr>
      <td>
        <asp:Panel id="PersonalizePanel" runat="Server" Visible="False">
          Information for Zip Code: <asp:Label id="ZipCodeLabel" Runat="Server" /><br />
          <!-- Information for Zip Code here. -->
          <br />
          <asp:LinkButton id="ChangeZipCodeButton" Runat="Server" Text="Change Your Zip Code"
                          OnClick="ChangeZipCode_OnClick" />
        </asp:Panel>
        <asp:Panel id="GetZipCodePanel" runat="Server" Visible="False">
          You can personalize this page by entering your Zip Code: 
          <asp:TextBox id="ZipCodeTextBox" Columns="5" MaxLength="5" runat="Server" />
          <asp:LinkButton id="EnterZipCodeButton" Runat="Server" Text="Go"
                          OnClick="EnterZipCode_OnClick" />
        </asp:Panel>
      </td>
    </tr>
  </table>
</form>

</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

Public Sub Page_PreRender()

  If Profile.ZipCode = Nothing Then
    PersonalizePanel.Visible = False
    GetZipCodePanel.Visible = True
  Else
    ZipCodeLabel.Text = Profile.ZipCode

    ' Get personalized information for zip code here.

    PersonalizePanel.Visible = True
    GetZipCodePanel.Visible = False
  End If

End Sub

Public Sub ChangeZipCode_OnClick(sender As Object, args As EventArgs)
  ZipCodeTextBox.Text = Profile.ZipCode
  Profile.ZipCode = Nothing

  PersonalizePanel.Visible = False
  GetZipCodePanel.Visible = True
End Sub

Public Sub EnterZipCode_OnClick(sender As Object, args As EventArgs)
  Profile.ZipCode = ZipCodeTextBox.Text
End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Home Page</title>
</head>
<body>

<form id="form1" runat="server">
  <table border="1" cellpadding="2" cellspacing="2">
    <tr>
      <td>
        <asp:Panel id="PersonalizePanel" runat="Server" Visible="False">
          Information for Zip Code: <asp:Label id="ZipCodeLabel" Runat="Server" /><br />
          <!-- Information for Zip Code here. -->
          <br />
          <asp:LinkButton id="ChangeZipCodeButton" Runat="Server" Text="Change Your Zip Code"
                          OnClick="ChangeZipCode_OnClick" />
        </asp:Panel>
        <asp:Panel id="GetZipCodePanel" runat="Server" Visible="False">
          You can personalize this page by entering your Zip Code: 
          <asp:TextBox id="ZipCodeTextBox" Columns="5" MaxLength="5" runat="Server" />
          <asp:LinkButton id="EnterZipCodeButton" Runat="Server" Text="Go"
                          OnClick="EnterZipCode_OnClick" />
        </asp:Panel>
      </td>
    </tr>
  </table>
</form>

</body>
</html>

다음 코드 예제에서는 사용자 지정 프로필을 만들기 위해 클래스에서 ProfileBase 상속되는 클래스를 정의합니다. 사용자 지정 프로필의 형식은 애플리케이션에 inherits 대한 Web.config 파일의 프로필 구성 요소 특성에 지정됩니다.

중요

이 예제에서는 잠재적 보안 위협을 사용자 입력을 허용 하는 텍스트 상자가 포함 되어 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

using System;
using System.Web.Profile;

namespace Samples.AspNet.Profile
{
  public class EmployeeProfile : ProfileBase
  {
    [SettingsAllowAnonymous(false)]
    [ProfileProvider("EmployeeInfoProvider")]
    public string Department
    {
      get { return base["EmployeeDepartment"].ToString(); }
      set { base["EmployeeDepartment"] = value; }
    }

    [SettingsAllowAnonymous(false)]
    [ProfileProvider("EmployeeInfoProvider")]
    public EmployeeInfo Details
    {
      get { return (EmployeeInfo)base["EmployeeInfo"]; }
      set { base["EmployeeInfo"] = value; }
    }
  }

  public class EmployeeInfo
  {
    public string Name;
    public string Address;
    public string Phone;
    public string EmergencyContactName;
    public string EmergencyContactAddress;
    public string EmergencyContactPhone;
  }
}
Imports System.Web.Profile

Namespace Samples.AspNet.Profile

  Public Class EmployeeProfile
    Inherits ProfileBase

    <SettingsAllowAnonymous(False)> _
    <ProfileProvider("EmployeeInfoProvider")> _
    Public Property Department As String
      Get
        Return MyBase.Item("EmployeeDepartment").ToString()
      End Get
      Set
        MyBase.Item("EmployeeDepartment") = value
      End Set
    End Property

    <SettingsAllowAnonymous(False)> _
    <ProfileProvider("EmployeeInfoProvider")> _
    Public Property Details As EmployeeInfo
      Get
        Return CType(MyBase.Item("EmployeeInfo"), EmployeeInfo)
      End Get
      Set
        MyBase.Item("EmployeeInfo") = value
      End Set
    End Property
  End Class

  Public Class EmployeeInfo
    Public Name As String
    Public Address As String
    Public Phone As String
    Public EmergencyContactName As String
    Public EmergencyContactAddress As String
    Public EmergencyContactPhone As String
  End Class

End Namespace

설명

ASP.NET을 사용 하는 ProfileBase 사용자 프로필에 사용 되는 클래스를 만드는 클래스입니다. 사용자 프로필을 사용 하는 애플리케이션 시작 되 면 ASP.NET 형식의 새 클래스를 만듭니다 ProfileCommon에서 상속 되는 ProfileBase 클래스입니다. 강력한 형식의 접근자는 프로필 구성 섹션에 ProfileCommon 정의된 각 속성에 대한 클래스에 추가됩니다. 클래스의 강력한 형식의 ProfileCommon 접근자가 각각 프로필 속성 값을 검색하고 SetPropertyValue 설정하기 위해 기본 클래스의 ProfileBase 메서드 및 메서드를 호출 GetPropertyValue 합니다. 인스턴스를 ProfileCommon 클래스의 값으로 설정 됩니다는 Profile ASP.NET 애플리케이션에 대 한 속성입니다.

ASP.NET 애플리케이션에서 사용자 프로필의 인스턴스를 만드는 것이 좋습니다 사용 하 여 Create 메서드.

상속자 참고

추상 클래스에서 상속하고 프로필 구성 요소에 ProfileBase 지정되지 않은 사용자 프로필의 속성을 정의하는 사용자 지정 프로필 구현을 만들 수 있습니다. 다음 예제와 inherits 같이 프로필 구성 요소의 특성을 사용하여 web.config 파일에서 사용자 지정 사용자 프로필 형식을 지정할 수 있습니다. 클래스에 EmployeeProfile 대한 코드는 이 항목의 예제 섹션에 포함되어 있습니다.

<configuration>
   <system.web>
      <profile inherits="Samples.AspNet.Profile.EmployeeProfile"  
      defaultProvider="SqlProvider">  
      <providers>  
         <clear />  
         <add  
            name="SqlProvider"  
            type="System.Web.Profile.SqlProfileProvider"   
            connectionStringName="SqlServices"   
            description="SQL Profile Provider for Sample"/>   
         <add  
            name="EmployeeInfoProvider"  
            type="System.Web.Profile.SqlProfileProvider"   
            connectionStringName="SqlServices"   
            description="SQL Profile Provider for Employee Info"/>   
      </providers>  
      
      <properties>  
         <add name="GarmentSize" />  
      </properties>  
      </profile>  
   </system.web>
</configuration>

생성자

ProfileBase()

ProfileBase 클래스의 인스턴스를 만듭니다.

속성

Context

연결된 설정 컨텍스트를 가져옵니다.

(다음에서 상속됨 SettingsBase)
IsAnonymous

사용자 프로필이 익명 사용자에 대한 프로필인지 여부를 나타내는 값을 가져옵니다.

IsDirty

프로필 속성이 수정되었는지 여부를 나타내는 값을 가져옵니다.

IsSynchronized

개체에 대한 액세스가 동기화되어 스레드로부터 안전한지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 SettingsBase)
Item[String]

속성 이름별로 인덱싱된 프로필 속성 값을 가져오거나 설정합니다.

LastActivityDate

프로필을 마지막으로 읽거나 수정한 날짜와 시간을 가져옵니다.

LastUpdatedDate

프로필을 마지막으로 수정한 날짜와 시간을 가져옵니다.

Properties

프로필의 각 속성에 대한 SettingsProperty 개체의 컬렉션을 가져옵니다.

PropertyValues

설정 속성 값의 컬렉션을 가져옵니다.

(다음에서 상속됨 SettingsBase)
Providers

설정 공급자의 컬렉션을 가져옵니다.

(다음에서 상속됨 SettingsBase)
UserName

프로필의 사용자 이름을 가져옵니다.

메서드

Create(String)

ASP.NET에서 지정된 사용자 이름에 대한 프로필의 인스턴스를 만드는 데 사용됩니다.

Create(String, Boolean)

ASP.NET에서 지정된 사용자 이름에 대한 프로필의 인스턴스를 만드는 데 사용됩니다. 사용자가 인증된 사용자인지, 아니면 익명 사용자인지 여부를 나타내는 매개 변수를 사용합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetProfileGroup(String)

그룹 이름으로 식별된 속성 그룹을 가져옵니다.

GetPropertyValue(String)

프로필 속성의 값을 가져옵니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
Initialize(SettingsContext, SettingsPropertyCollection, SettingsProviderCollection)

SettingsBase 개체가 사용하는 내부 속성을 초기화합니다.

(다음에서 상속됨 SettingsBase)
Initialize(String, Boolean)

현재 사용자에 대한 프로필 속성 값과 정보를 초기화합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Save()

프로필 데이터 소스를 변경된 프로필 속성 값으로 업데이트합니다.

SetPropertyValue(String, Object)

프로필 속성의 값을 설정합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보