ProfileBase.SetPropertyValue(String, Object) Método

Definição

Define o valor de uma propriedade de perfil.Sets the value of a profile property.

public:
 void SetPropertyValue(System::String ^ propertyName, System::Object ^ propertyValue);
public void SetPropertyValue (string propertyName, object propertyValue);
member this.SetPropertyValue : string * obj -> unit
Public Sub SetPropertyValue (propertyName As String, propertyValue As Object)

Parâmetros

propertyName
String

O nome da propriedade a ser definida.The name of the property to set.

propertyValue
Object

O valor a ser atribuído à propriedade.The value to assign to the property.

Exceções

Foi feita uma tentativa de definir um valor da propriedade em um perfil anônimo em que o atributo allowAnonymous da propriedade é false.An attempt was made to set a property value on an anonymous profile where the property's allowAnonymous attribute is false.

Não existem propriedades definidas para o perfil atual.There are no properties defined for the current profile.

- ou --or-

O nome da propriedade de perfil especificado não existe no perfil atual.The specified profile property name does not exist in the current profile.

- ou --or-

O provedor para a propriedade do perfil especificado não reconheceu a propriedade especificada.The provider for the specified profile property did not recognize the specified property.

Foi feita uma tentativa de definir um valor em uma propriedade marcada como somente leitura.An attempt was made to set a value on a property that was marked as read-only.

Foi feita uma tentativa de atribuir um valor a uma propriedade usando um tipo incompatível.An attempt was made to assign a value to a property using an incompatible type.

Exemplos

O exemplo de código a seguir mostra uma página ASP.NET que lê e define a ZipCode propriedade especificada para o perfil do usuário.The following code example shows an ASP.NET page that reads and sets the ZipCode property specified for the user profile. Para obter um exemplo de um arquivo de Web.config que especifica Propriedades para o perfil de usuário, consulte o exemplo fornecido para a ProfileBase classe.For an example of a Web.config file that specifies properties for the user profile, see the example provided for the ProfileBase class.

Importante

Este exemplo contém uma caixa de texto que aceita a entrada do usuário, que é uma possível ameaça à segurança.This example contains a text box that accepts user input, which is a potential security threat. Por padrão, as páginas da Web do ASP.NET validam que a entrada do usuário não inclui elementos de script ou HTML.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. Para obter mais informações, consulte Visão geral de explorações de script.For more information, see Script Exploits Overview.

<%@ 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>

Comentários

ASP.NET usa a ProfileBase classe para criar a classe usada para o perfil do usuário.ASP.NET uses the ProfileBase class to create the class used for the user profile. Quando um aplicativo que tem o perfil de usuário habilitado é iniciado, o ASP.NET cria uma nova classe do tipo ProfileCommon , que é herdada da ProfileBase classe.When an application that has the user profile enabled is started, ASP.NET creates a new class of type ProfileCommon, which inherits from the ProfileBase class. Acessadores com rigidez de tipos são adicionados à ProfileCommon classe para cada propriedade definida na seção de configuração do perfil .Strongly typed accessors are added to the ProfileCommon class for each property defined in the profile configuration section. Os acessadores com rigidez de tipos da ProfileCommon classe chamam o SetPropertyValue método para passar valores de propriedade para o ProfileProvider a ser armazenado na fonte de dados.The strongly typed accessors of the ProfileCommon class call the SetPropertyValue method to pass property values to the ProfileProvider to be stored at the data source.

Você pode usar o SetPropertyValue método para atribuir valores de propriedade no perfil do usuário para seu aplicativo por nome.You can use the SetPropertyValue method to assign property values in the user profile for your application by name. Os valores são sem tipo e a verificação de tipo será feita em tempo de execução, não em tempo de compilação.Values are untyped, and type checking will be done at run time, not compile time. Para acesso com rigidez de tipos a valores de propriedade de perfil, você pode acessar a propriedade por nome como um membro da Profile propriedade que está disponível em cada página, por exemplo, Profile.CustomerAddress .For strongly typed access to profile property values, you can access the property by name as a member of the Profile property that is available on each page, for example, Profile.CustomerAddress.

Aplica-se a