ProfileBase.GetProfileGroup(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 un groupe de propriétés identifiées par un nom de groupe.
public:
System::Web::Profile::ProfileGroupBase ^ GetProfileGroup(System::String ^ groupName);
public System.Web.Profile.ProfileGroupBase GetProfileGroup(string groupName);
member this.GetProfileGroup : string -> System.Web.Profile.ProfileGroupBase
Public Function GetProfileGroup (groupName As String) As ProfileGroupBase
Paramètres
- groupName
- String
Nom du groupe de propriétés.
Retours
Objet ProfileGroupBase d’un groupe de propriétés configuré avec le nom de groupe spécifié.
Exceptions
Le nom du groupe de propriétés de profil spécifié n’a pas été trouvé dans la section configuration des propriétés .
Exemples
Le fichier Web.config suivant spécifie un profil utilisateur qui contient un groupe de propriétés avec un nom de groupe de Address. Les propriétés groupées générées pour la Profile propriété actuelle HttpContext sont précédées du nom du groupe. Par exemple : Profile.Address.Street.
<configuration>
<connectionStrings>
<add name="SqlServices" connectionString=
"Data Source=localhost;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />
</connectionStrings>
<system.web>
<authentication mode="Forms" >
<forms loginUrl="login.aspx"
name=".ASPXFORMSAUTH" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
<membership defaultProvider="SqlProvider"
userIsOnlineTimeWindow="15">
<providers>
<clear />
<add
name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="SqlServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="false"
passwordFormat="Hashed"
applicationName="MyApplication" />
</providers>
</membership>
<profile defaultProvider="SqlProvider">
<providers>
<add
name="SqlProvider"
connectionStringName="SqlServices"
applicationName="MyApplication"
type="System.Web.Profile.SqlProfileProvider" />
</providers>
<properties>
<add name="ZipCode" />
<group name="Address">
<add name="Street" />
<add name="City" />
<add name="State" />
<add name="CountryOrRegion" />
</group>
</properties>
</profile>
</system.web>
</configuration>
La page ASP.NET suivante lit et définit les propriétés groupées spécifiées pour le profil utilisateur.
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, ASP.NET pages web valident que l’entrée utilisateur n’inclut pas de script ou d’éléments HTML. Pour plus d’informations, consultez Vue d’ensemble des exploits 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_Load()
{
if (!IsPostBack)
{
StreetTextBox.Text = Profile.Address.Street;
CityTextBox.Text = Profile.Address.City;
StateTextBox.Text = Profile.Address.State;
CountryOrRegionTextBox.Text = Profile.Address.CountryOrRegion;
ZipCodeTextBox.Text = Profile.ZipCode;
}
}
public void UpdateButton_OnClick(object sender, EventArgs args)
{
Profile.Address.Street = StreetTextBox.Text;
Profile.Address.City = CityTextBox.Text;
Profile.Address.State = StateTextBox.Text;
Profile.Address.CountryOrRegion = CountryOrRegionTextBox.Text;
Profile.ZipCode = ZipCodeTextBox.Text;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Home Page</title>
</head>
<body>
<h3>Address Information for <%=User.Identity.Name%></h3>
<form id="form1" runat="server">
<table border="1" cellpadding="2" cellspacing="2">
<tr>
<td>Street Address</td>
<td><asp:Textbox id="StreetTextBox" runat="server" columns="30" /></td>
</tr>
<tr>
<td>City</td>
<td><asp:Textbox id="CityTextBox" runat="server" columns="20" /></td>
</tr>
<tr>
<td>State</td>
<td><asp:Textbox id="StateTextBox" runat="server" columns="20" /></td>
</tr>
<tr>
<td>Zip Code</td>
<td><asp:Textbox id="ZipCodeTextBox" runat="server" columns="10" /></td>
</tr>
<tr>
<td>Country</td>
<td><asp:Textbox id="CountryOrRegionTextBox" runat="server" columns="20" /></td>
</tr>
</table>
<asp:Button id="UpdateButton" runat="server" OnClick="UpdateButton_OnClick" Text="Update Address" />
</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_Load()
If Not IsPostBack Then
StreetTextBox.Text = Profile.Address.Street
CityTextBox.Text = Profile.Address.City
StateTextBox.Text = Profile.Address.State
CountryOrRegionTextBox.Text = Profile.Address.CountryOrRegion
ZipCodeTextBox.Text = Profile.ZipCode
End If
End Sub
Public Sub UpdateButton_OnClick(sender As Object, args As EventArgs)
Profile.Address.Street = StreetTextBox.Text
Profile.Address.City = CityTextBox.Text
Profile.Address.State = StateTextBox.Text
Profile.Address.CountryOrRegion = CountryOrRegionTextBox.Text
Profile.ZipCode = ZipCodeTextBox.Text
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Home Page</title>
</head>
<body>
<h3>Address Information for <%=User.Identity.Name%></h3>
<form id="form1" runat="server">
<table border="1" cellpadding="2" cellspacing="2">
<tr>
<td>Street Address</td>
<td><asp:Textbox id="StreetTextBox" runat="server" columns="30" /></td>
</tr>
<tr>
<td>City</td>
<td><asp:Textbox id="CityTextBox" runat="server" columns="20" /></td>
</tr>
<tr>
<td>State</td>
<td><asp:Textbox id="StateTextBox" runat="server" columns="20" /></td>
</tr>
<tr>
<td>Zip Code</td>
<td><asp:Textbox id="ZipCodeTextBox" runat="server" columns="10" /></td>
</tr>
<tr>
<td>Country</td>
<td><asp:Textbox id="CountryOrRegionTextBox" runat="server" columns="20" /></td>
</tr>
</table>
<asp:Button id="UpdateButton" runat="server" OnClick="UpdateButton_OnClick" Text="Update Address" />
</form>
</body>
</html>
Remarques
Les propriétés de profil peuvent être séparées en groupes pour une meilleure organisation. La GetProfileGroup(String) méthode peut être utilisée pour récupérer un groupe de propriétés par le nom du groupe. Vous pouvez également accéder à une propriété de profil dans un groupe en spécifiant le nom du groupe en tant que membre de la Profile propriété disponible sur chaque page. Par exemple, la ZipCode propriété de profil membre du groupe de profils est accessible à l’aide Profile.Address.ZipCodeAddress de .