ProfileBase.GetPropertyValue(String) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient la valeur d'une propriété de profil.
public:
System::Object ^ GetPropertyValue(System::String ^ propertyName);
public object GetPropertyValue (string propertyName);
member this.GetPropertyValue : string -> obj
Public Function GetPropertyValue (propertyName As String) As Object
Paramètres
- propertyName
- String
Nom de la propriété de profil.
Retours
La valeur de la propriété de profil spécifiée, de type object
Exceptions
Une tentative de définition d'une valeur de propriété pour un profil anonyme a été effectuée pour une propriété dont l'attribut allowAnonymous
est false
.
Aucune propriété n'est définie pour le profil actuel.
- ou -
Le nom de propriété de profil spécifié n'existe pas dans le profil actuel.
- ou -
Le fournisseur de la propriété de profil spécifiée n'a pas reconnu la propriété spécifiée.
Exemples
L’exemple de code suivant montre une page ASP.NET qui lit et définit la ZipCode
propriété spécifiée pour le profil utilisateur. Pour obtenir un exemple d’un fichier Web.config qui spécifie les propriétés du profil utilisateur, consultez l’exemple fourni pour la ProfileBase classe.
Important
Cet exemple contient une zone de texte qui accepte l’entrée utilisateur, qui est une menace de sécurité potentielle. Par défaut, les pages web ASP.NET vérifient que l’entrée d’utilisateur n’inclut pas de script ou d’éléments HTML. Pour plus d’informations, consultez Vue d’ensemble des attaques de script.
<%@ 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>
Remarques
ASP.NET utilise la ProfileBase classe pour créer la classe utilisée pour le profil utilisateur. Lorsqu’une application sur laquelle le profil utilisateur est activé est démarrée, ASP.NET crée une classe de typeProfileCommon
, qui hérite de la ProfileBase classe. Les accesseurs fortement typés sont ajoutés à la ProfileCommon
classe pour chaque propriété définie dans la section configuration du profil . Les accesseurs fortement typés de la ProfileCommon
classe appellent la GetPropertyValue méthode pour récupérer des valeurs non typées à partir de celui ProfileProvider que l’accesseur généré effectue ensuite un cast en tant que type spécifié et retourne comme valeur de propriété.
Vous pouvez utiliser la GetPropertyValue méthode pour récupérer les valeurs de propriété du profil utilisateur de votre application par nom. Les valeurs retournées ne sont pas typées et doivent être castées en tant que type d’objet spécifique lors de la récupération. Pour un accès fortement typé aux valeurs de propriété de profil, vous pouvez accéder à la propriété par nom en tant que membre de la propriété Profil disponible sur chaque page, Profile.CustomerAddress
par exemple.