Aracılığıyla paylaş


SiteMapProvider.Initialize(String, NameValueCollection) Yöntem

Tanım

Kalıcı depolama alanından SiteMapProvider site eşleme verilerini yüklemek için gereken tüm kaynaklar dahil olmak üzere uygulamayı başlatır.

public:
 override void Initialize(System::String ^ name, System::Collections::Specialized::NameValueCollection ^ attributes);
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection attributes);
override this.Initialize : string * System.Collections.Specialized.NameValueCollection -> unit
Public Overrides Sub Initialize (name As String, attributes As NameValueCollection)

Parametreler

name
String

Başlatacak Name sağlayıcının.

attributes
NameValueCollection

NameValueCollection Sağlayıcıyı başlatmaya yardımcı olmak için ek öznitelikler içerebilen bir. Bu öznitelikler, Web.config dosyasındaki site haritası sağlayıcısı yapılandırmasından okunur.

Örnekler

Aşağıdaki kod örneği, Microsoft Access veritabanı bağlantısını hazırlamak için yönteminin nasıl geçersiz kılınduğunu Initialize gösterir.

Nesnesinin OleDbConnection bağlantı dizesi, yönteminin NameValueCollection parametresinde Initialize geçirilir. Bu durumda, bağlantı dizesi Web.config dosyasındaki sağlayıcıya özgü bölüm tarafından sağlanır. Burada, accessSiteMapConnectionString site haritası verilerini barındıran bir Microsoft Access veritabanına bağlantı dizesi içerir.

<siteMap defaultProvider="AccessSiteMapProvider">
  <providers>
     <add
       name="AccessSiteMapProvider"
       type="Samples.AspNet.AccessSiteMapProvider,Samples.AspNet"
       accessSiteMapConnectionString="PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=\\SomeUNCShare\\sitemap.mdb"/>
  </providers>
 </siteMap>

Bu kod örneği, sınıfı için SiteMapProvider sağlanan daha büyük bir örneğin parçasıdır.

   // Initialize is used to initialize the properties and any state that the
   // AccessProvider holds, but is not used to build the site map.
   // The site map is built when the BuildSiteMap method is called.
   virtual void Initialize( String^ name, NameValueCollection^ attributes ) override
   {
      if ( IsInitialized )
            return;

      StaticSiteMapProvider::Initialize( name, attributes );
      
      // Create and test the connection to the Microsoft Access database.
      // Retrieve the Value of the Access connection string from the
      // attributes NameValueCollection.
      String^ connectionString = attributes[ AccessConnectionStringName ];
      if ( nullptr == connectionString || connectionString->Length == 0 )
            throw gcnew Exception( "The connection string was not found." );
      else
            accessConnection = gcnew OleDbConnection( connectionString );

      initialized = true;
   }


protected:
// Initialize is used to initialize the properties and any state that the
// AccessProvider holds, but is not used to build the site map.
// The site map is built when the BuildSiteMap method is called.
public override void Initialize(string name, NameValueCollection attributes) {
    if (IsInitialized)
        return;

    base.Initialize(name, attributes);

    // Create and test the connection to the Microsoft Access database.

    // Retrieve the Value of the Access connection string from the
    // attributes NameValueCollection.
    string connectionString = attributes[AccessConnectionStringName];

    if (null == connectionString || connectionString.Length == 0)
        throw new Exception ("The connection string was not found.");
    else
        accessConnection = new OleDbConnection(connectionString);

    initialized = true;
}
' Initialize is used to initialize the properties and any state that the
' AccessProvider holds, but is not used to build the site map.
' The site map is built when the BuildSiteMap method is called.
Public Overrides Sub Initialize(ByVal name As String, ByVal attributes As NameValueCollection)
    If IsInitialized Then
        Return
    End If
    MyBase.Initialize(name, attributes)

    ' Create and test the connection to the Microsoft Access database.
    ' Retrieve the Value of the Access connection string from the
    ' attributes NameValueCollection.
    Dim connectionString As String = attributes(AccessConnectionStringName)

    If Nothing = connectionString OrElse connectionString.Length = 0 Then
        Throw New Exception("The connection string was not found.")
    Else
        accessConnection = New OleDbConnection(connectionString)
    End If
    initialized = True
End Sub

Açıklamalar

Initialize yöntemi aslında bir site haritası oluşturmaz, yalnızca nesnenin SiteMapProvider durumunu bunu yapmak için hazırlar. Varsayılan uygulama, site gezinti yapılandırmasından site haritası sağlayıcısının özelliğini başlatır SecurityTrimmingEnabled .

'den SiteMapProvider türetilen sınıflar, kalıcı depolama alanından site eşleme verilerini yüklemek için gereken tüm durumları ve kaynakları başlatmak için yöntemini geçersiz kılabilir Initialize . Örneğin, türetilmiş sınıfınız site haritası verilerini depolamak için dosyalar kullanıyorsa, yönteminde Initialize herhangi bir dosya başlatma gerçekleştirilebilir. Türetilen sınıf ilişkisel veritabanı gibi başka türde bir veri deposu kullanıyorsa, veritabanı bağlantısı başlatılabilir.

Dosya adları veya bağlantı dizeleri gibi ek öznitelikler, ASP.NET yapılandırma sistemi tarafından okunur ve parametresiyle NameValueCollection yöntemine Initialize geçirilir.

Devralanlara Notlar

Türetilmiş bir sınıfta yöntemini geçersiz kıldığınızda Initialize(String, NameValueCollection) , kendi başlatmalarınızı gerçekleştirmeden önce temel sınıf için yöntemini çağırdığınızdan Initialize(String, NameValueCollection) emin olun.

Şunlara uygulanır

Ayrıca bkz.