ProfileBase.Item[String] 속성

정의

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

public:
 virtual property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ propertyName); void set(System::String ^ propertyName, System::Object ^ value); };
public override object this[string propertyName] { get; set; }
member this.Item(string) : obj with get, set
Default Public Overrides Property Item(propertyName As String) As Object

매개 변수

propertyName
String

프로필 속성의 이름입니다.

속성 값

Object

object로 형식화된, 지정된 프로필 속성의 값입니다.

예외

속성의 allowAnonymous 특성이 false일 때 익명 프로필에 대한 속성 값을 설정하려고 한 경우

현재 프로필에 대해 정의된 속성이 없는 경우

또는

지정된 프로필 속성 이름이 현재 프로필에 없는 경우

또는

지정된 프로필 속성의 공급자가 지정된 속성을 인식하지 못한 경우

읽기 전용으로 표시된 속성 값을 설정하려고 한 경우

호환되지 않는 형식을 사용하여 속성에 값을 할당하려고 한 경우

예제

다음 코드 예제에서는 개체의 정적 Properties 컬렉션에서 컨트롤에 속성을 바인딩 Name 하여 사용자 프로필의 SettingsProperty 속성 이름을 나열합니다GridView. 선택한 속성 값은 컬렉션을 사용하여 이름으로 검색됩니다 Item[] . 사용자 프로필의 속성을 지정하는 Web.config 파일의 예제는 클래스에 제공된 예제를 ProfileBase 참조하세요.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Profile" %>

<!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_Load()
{
  if (!IsPostBack)
  {
    PropertiesListBox.DataSource = ProfileBase.Properties;
    PropertiesListBox.DataBind();
  }

  if (PropertiesListBox.SelectedItem != null)
  {
    object propValue = Profile[PropertiesListBox.SelectedItem.Text];

    Type propType = propValue.GetType();

    // If the property is a value type, return ToString().

    if (propType == typeof(string) || propType.IsValueType)
    {
      ValueLabel.Visible = true;
      ValueGridView.Visible = false;
      ValueLabel.Text = propValue.ToString();
      return;
    }


    // Bind the property to a GridView.

    try
    {
      ValueGridView.DataSource = propValue;
      ValueGridView.DataBind();
      ValueGridView.Visible = true;
      ValueLabel.Visible = false; 
    }
    catch
    {
      // If the property is not bindable, return ToString().

      ValueLabel.Visible = true;
      ValueGridView.Visible = false;
      ValueLabel.Text = propValue.ToString();
    }
  }
}

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

<h3>View Profile properties:</h3>

<form id="form1" runat="server">
  <table border="0" cellpadding="2" cellspacing="2">
    <tr>
      <td>Property</td>
      <td>Value</td>
    </tr>
    <tr>
      <td valign="top">
        <asp:ListBox runat="server" id="PropertiesListBox" Rows="10" AutoPostBack="True" DataTextField="Name" />
      </td>
      <td valign="top">
        <asp:GridView runat="Server" id="ValueGridView" Visible="False" />
        <asp:Label runat="Server" id="ValueLabel" Visible="False" />
      </td>
    </tr>
  </table>
</form>

</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Profile" %>

<!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_Load()

  If Not IsPostBack Then
    PropertiesListBox.DataSource = ProfileBase.Properties
    PropertiesListBox.DataBind()
  End If

  If Not PropertiesListBox.SelectedItem Is Nothing Then
    Dim propValue As Object = Profile(PropertiesListBox.SelectedItem.Text)

    Dim propType As Type = propValue.GetType()

    ' If the property is a value type, return ToString().

    If propType Is GetType(String) Or propType.IsValueType Then
      ValueLabel.Visible = True
      ValueGridView.Visible = False
      ValueLabel.Text = propValue.ToString()
      Return
    End If


    ' Bind the property to a GridView.

    Try
      ValueGridView.DataSource = propValue
      ValueGridView.DataBind()
      ValueGridView.Visible = True
      ValueLabel.Visible = False 
    Catch
      ' If the property is not bindable, return ToString().

      ValueLabel.Visible = True
      ValueGridView.Visible = False
      ValueLabel.Text = propValue.ToString()
    End Try
  End If
End Sub

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

<h3>View Profile properties:</h3>

<form id="form1" runat="server">
  <table border="0" cellpadding="2" cellspacing="2">
    <tr>
      <td>Property</td>
      <td>Value</td>
    </tr>
    <tr>
      <td valign="top">
        <asp:ListBox runat="server" id="PropertiesListBox" Rows="10" AutoPostBack="True" DataTextField="Name" />
      </td>
      <td valign="top">
        <asp:GridView runat="Server" id="ValueGridView" Visible="False" />
        <asp:Label runat="Server" id="ValueLabel" Visible="False" />
      </td>
    </tr>
  </table>
</form>

</body>
</html>

설명

이 속성을 사용 하 여 검색 또는 이름으로 애플리케이션에 대 한 사용자 프로필의 속성 값을 설정할 수 있습니다. 반환 된 값으로 형식화 됩니다 object 및 검색할 때 특정 개체 형식으로 캐스팅 해야 합니다. 프로필 속성 값에 대한 강력한 형식의 액세스의 경우 각 페이지에서 사용할 수 있는 속성의 Profile 멤버로 이름으로 속성에 액세스할 수 있습니다. 예를 들면 다음과 같습니다 Profile.CustomerAddress.

적용 대상

추가 정보