ProfileBase Costruttore
Definizione
Crea un'istanza della classe ProfileBase.Creates an instance of the ProfileBase class.
public:
ProfileBase();
public ProfileBase ();
Public Sub New ()
Eccezioni
L'attributo enabled
della sezione profile del file Web.config è false
.The enabled
attribute of the profile section of the Web.config file is false
.
Non è stato possibile creare un tipo di proprietà specificato nella sezione profile del file Web.config.A property type specified in the profile section of the Web.config file could not be created.
-oppure--or-
L'attributo allowAnonymous
di una proprietà nella sezione profile del file Web.config è impostato su true
e l'attributo enabled
dell'elemento <anonymousIdentification> è impostato su false
.The allowAnonymous
attribute for a property in the profile section of the Web.config file is set to true
and the enabled
attribute of the <anonymousIdentification> element is set to false
.
-oppure--or-
L'attributo serializeAs
di una proprietà nella sezione profile del file Web.config è impostato su Binary e la proprietà IsSerializable di type
specificato restituisce false
.The serializeAs
attribute for a property in the profile section of the Web.config file is set to Binary and the IsSerializable property of the specified type
returns false
.
-oppure--or-
Non è stato possibile trovare il nome di un provider specificato mediante l'attributo provider
di una proprietà del profilo nell'insieme Providers.The name of a provider specified using the provider
attribute of a profile property could not be found in the Providers collection.
-oppure--or-
Non è stato possibile trovare il type
specificato per una proprietà del profilo.The type
specified for a profile property could not be found.
-oppure--or-
Una proprietà del profilo è stata specificata con un nome corrispondente a una proprietà nella classe base specificata nell'attributo inherits
della sezione profile.A profile property was specified with a name that matches a property name on the base class specified in the inherits
attribute of the profile section.
Esempio
Il file di Web.config seguente specifica un profilo utente che contiene una ZipCode
proprietà di tipo string
e una RecentSearchList
proprietà di tipo StringCollection .The following Web.config file specifies a user profile that contains a ZipCode
property of type string
and a RecentSearchList
property of type StringCollection. La Profile proprietà generata dell'oggetto corrente HttpContext avrà funzioni di accesso fortemente tipizzate per ogni proprietà specificata.The generated Profile property of the current HttpContext will have strongly typed accessors for each of the specified properties.
<configuration>
<connectionStrings>
<add name="SqlServices" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />
</connectionStrings>
<system.web>
<anonymousIdentification enabled="true" />
<profile defaultProvider="SqlProvider" >
<providers>
<add
name="SqlProvider"
connectionStringName="SqlServices"
applicationName="ProfileBaseApplication"
type="System.Web.Profile.SqlProfileProvider" />
</providers>
<properties>
<add name="ZipCode" allowAnonymous="true" />
<add name="RecentSearchList"
type="System.Collections.Specialized.StringCollection"
serializeAs="Xml"
allowAnonymous="true" />
</properties>
</profile>
</system.web>
</configuration>
La pagina ASP.NET seguente legge e imposta la ZipCode
proprietà specificata per il profilo utente.The following ASP.NET page reads and sets the ZipCode
property specified for the user profile.
Importante
Questo esempio contiene una casella di testo che accetta l'input dell'utente, che rappresenta una potenziale minaccia per la sicurezza.This example contains a text box that accepts user input, which is a potential security threat. Per impostazione predefinita, le pagine Web ASP.NET verificano che l'input dell'utente non includa script o elementi HTML.By default, ASP.NET Web pages validate that user input does not include script or HTML elements. Per altre informazioni, vedere Cenni preliminari sugli attacchi tramite 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>
Commenti
ASP.NET usa la ProfileBase classe per creare la classe usata per il profilo utente.ASP.NET uses the ProfileBase class to create the class used for the user profile. Quando viene avviata un'applicazione con il profilo utente abilitato, ASP.NET crea una nuova classe di tipo ProfileCommon
, che eredita dalla 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. Le funzioni di accesso fortemente tipizzate vengono aggiunte alla ProfileCommon
classe per ogni proprietà definita nella sezione di configurazione del profilo .Strongly typed accessors are added to the ProfileCommon
class for each property defined in the profile configuration section. Le funzioni di accesso fortemente tipizzate della ProfileCommon
classe chiamano GetPropertyValue i SetPropertyValue metodi e della ProfileBase classe di base per recuperare e impostare rispettivamente i valori delle proprietà del profilo.The strongly typed accessors of the ProfileCommon
class call the GetPropertyValue and SetPropertyValue methods of the ProfileBase base class to retrieve and set profile property values, respectively. Un'istanza della ProfileCommon
classe viene impostata come valore della Profile proprietà per l'applicazione ASP.NET.An instance of the ProfileCommon
class is set as the value of the Profile property for the ASP.NET application.
Nota
La classe di base utilizzata per generare la classe archiviata nella Profile proprietà può essere sottoposta a override utilizzando l' inherits
attributo della sezione del profilo del file di configurazione.The base class used to generate the class stored in the Profile property can be overridden using the inherits
attribute of the profile section of the configuration file. In questo caso è necessario specificare una classe personalizzata che eredita dalla ProfileBase classe di base.In this case you would specify a custom class that inherits from the ProfileBase base class.
Questo costruttore non è destinato a essere utilizzato dal codice dell'applicazione.This constructor is not intended to be used from application code. Per creare un'istanza di un profilo utente, utilizzare il Create metodo.To create an instance of a user profile, use the Create method.