Compartilhar via


Como: Localizar dados de um MAP de site

You can localize the following properties in a site map:

These properties are localized by using an explicit or implicit expression as the value of the property.For more information about expressions, see Visão Geral sobre Expressões do ASP.NET.For information about resource files, see Recursos em aplicativos da Web.

To localize the Title or Description properties of a site-map node by using an explicit expression

  1. In your site map, set the EnableLocalization property to true.For example, in a Web.sitemap file, change the <siteMap> node to look like the following code:

    <siteMap enableLocalization="true">
    
  2. In your site map, change the value of the property that you want to localize to a resource string, such as the following case-sensitive line of code:

    $resources:ClassName,KeyName,DefaultValue
    

    For example, in a Web.sitemap file, your site-map node might look like the following example code.

    <siteMapNode 
      url="~/Home.aspx" 
      title="$resources:SiteMapLocalizations,HomePageTitle"
    description="$resources:SiteMapLocalizations,HomePageDescription,Default description"
      myCustomAttribute="$resources: CustomLocalizations,MyCustomAttribute"
    />
    

    The localized title and description are obtained from a file called SiteMapLocalizations.resx, by using the HomePageTitle and HomePageDescription resource keys.O atributo personalizado localizado é obtido de um arquivo separado chamado CustomLocalizations.resx.Para obter mais informações sobre seqüências de recursos, consulte Visão Geral sobre Expressões do ASP.NET.

  3. Create your .resx files in a folder called App_GlobalResources in the root of your application.Within the .resx file, individual property values are indexed by the value of the key name.For the preceding example, the SiteMapLocalizations.resx file might look like the following.

    <?xml version="1.0" encoding="utf-8"?>
    <root>
      <xsd:schema id="root"  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
        <xsd:element name="root" msdata:IsDataSet="true">
          <xsd:complexType>
            <xsd:choice maxOccurs="unbounded">
              <xsd:element name="metadata">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="value" type="xsd:string" minOccurs="0" />
                  </xsd:sequence>
                  <xsd:attribute name="name" type="xsd:string" />
                  <xsd:attribute name="type" type="xsd:string" />
                  <xsd:attribute name="mimetype" type="xsd:string" />
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="assembly">
                <xsd:complexType>
                  <xsd:attribute name="alias" type="xsd:string" />
                  <xsd:attribute name="name" type="xsd:string" />
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="data">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                    <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
                  </xsd:sequence>
                  <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
                  <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
                  <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="resheader">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                  </xsd:sequence>
                  <xsd:attribute name="name" type="xsd:string" use="required" />
                </xsd:complexType>
              </xsd:element>
            </xsd:choice>
          </xsd:complexType>
        </xsd:element>
      </xsd:schema>
      <resheader name="resmimetype">
        <value>text/microsoft-resx</value>
      </resheader>
      <resheader name="version">
        <value>2.0</value>
      </resheader>
      <resheader name="reader">
        <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
      </resheader>
      <resheader name="writer">
        <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
      </resheader>
      <data name="HomePageTitle">
        <value xml:space="preserve">Home Page</value>
      </data>
      <data name="HomePageDescription">
        <value xml:space="preserve">Home page of site</value>
      </data>
    </root>
    
  4. Se você precisar fazer localizar sequências para vários idiomas, você pode criar arquivos .resx adicionais com informações de localidade incluídas no nome do arquivo.For example, the French version of your resource file would be named SiteMapLocalizations.fr.resx.

To localize the Title or Description properties of a site-map node by using an implicit expression

  1. In your site map, set the EnableLocalization property to true.For example, in a Web.sitemap file, change the <siteMap> node to look like the following code:

    <siteMap enableLocalization="true">
    
  2. In your site map, add an attribute called resourceKey to the site-map node that you want to localize by using the following case-sensitive line of code:

    resourceKey="HomePage"
    

    For example, in a Web.sitemap file, your <siteMap> node might look like the following code:

    <siteMapNode 
      url="~/Home.aspx" 
      resourceKey="HomePage"
      title = "Default Title"   
      description = "Default Description" 
     />
    

    The localized title and description are obtained from a file called Web.sitemap.resx using the HomePage.title and HomePage.description resource keys.

  3. Create your .resx file in a folder called App_GlobalResources in the root of your application.Within the .resx file, individual property values are indexed by the name.For the preceding example, the Web.sitemap.resx file might look like the following.

    Observação:

    Key names in global resource files should not include periods (.).However, periods are necessary in global resources that are referenced in site-map files when using implicit expressions.This is because of the resourceKey syntax.In some editing environments, such as Visual Web Developer, you might get a design-time error if you use a period in the key name.However, this shouldn't affect the ability to edit or save the file and can be ignored.

    <?xml version="1.0" encoding="utf-8"?>
    <root>
      <xsd:schema id="root"  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
        <xsd:element name="root" msdata:IsDataSet="true">
          <xsd:complexType>
            <xsd:choice maxOccurs="unbounded">
              <xsd:element name="metadata">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="value" type="xsd:string" minOccurs="0" />
                  </xsd:sequence>
                  <xsd:attribute name="name" type="xsd:string" />
                  <xsd:attribute name="type" type="xsd:string" />
                  <xsd:attribute name="mimetype" type="xsd:string" />
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="assembly">
                <xsd:complexType>
                  <xsd:attribute name="alias" type="xsd:string" />
                  <xsd:attribute name="name" type="xsd:string" />
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="data">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                    <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
                  </xsd:sequence>
                  <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
                  <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
                  <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
                </xsd:complexType>
              </xsd:element>
              <xsd:element name="resheader">
                <xsd:complexType>
                  <xsd:sequence>
                    <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                  </xsd:sequence>
                  <xsd:attribute name="name" type="xsd:string" use="required" />
                </xsd:complexType>
              </xsd:element>
            </xsd:choice>
          </xsd:complexType>
        </xsd:element>
      </xsd:schema>
      <resheader name="resmimetype">
        <value>text/microsoft-resx</value>
      </resheader>
      <resheader name="version">
        <value>2.0</value>
      </resheader>
      <resheader name="reader">
        <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
      </resheader>
      <resheader name="writer">
        <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
      </resheader>
      <data name="HomePage.description">
        <value xml:space="preserve">Home Page Description</value>
      </data>
      <data name="HomePage.Text">
        <value xml:space="preserve">Home Page Text from Resource File</value>
      </data>
      <data name="HomePage.title">
        <value xml:space="preserve">Home Page Title from Resource File</value>
      </data>
      <assembly alias="mscorlib" name="mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <data name="LabelResource1.Visible" type="System.Boolean, mscorlib">
        <value>True</value>
      </data>
    </root>
    
  4. Se você precisar fazer localizar sequências para vários idiomas, você pode criar arquivos .resx adicionais com informações de localidade incluídas no nome do arquivo.For example, the French version of your resource file would be named Web.sitemap.fr.resx.

Localizing the URL Property in a Site Map

The Url property cannot be localized in a site map in the same way as the Title and Description properties.

To define different navigational structures based on a user's locale

  1. Define a different site-map file for each locale.

  2. Add each site map to the Web.config file.Para obter mais informações, consulte Como: configurar Multiple Site Maps and Site Map Providers.

  3. Programmatically switch to the appropriate Provider at run time.This is done by setting the SiteMapProvider property of the SiteMapDataSource object, or by setting the SiteMapProvider property of the SiteMapPath object, to the name of the provider.Para obter mais informações, consulte Como: Modificar programaticamente Site Map Nodes in memória.

Programação robusta

Explicit and implicit expressions can not be used in the same site-map file.

Consulte também

Tarefas

Como: configurar Multiple Site Maps and Site Map Providers

Como: Modificar programaticamente Site Map Nodes in memória

Conceitos

Mapas do Site do ASP.NET

Recursos em aplicativos da Web

Visão Geral sobre Expressões do ASP.NET

Tornando navegação em sites do ASP.NET seguro

Proteção de acesso a dados

Referência

Title

Description

Attributes

Outros recursos

Segurança de aplicativos ASP.NET em ambientes hospedados