SiteMap全球化无法正常工作

时间:2012-06-26 11:52:00

标签: asp.net localization sitemap globalization aspmenu

以下信息是关于在法国展示语言的全部信息。 但它没有显示任何数据原因? 我尝试了很多方法,但没有用。 我尝试了很多方法,但没有用。 我尝试了很多方法但没用。

     <?xml version="1.0" encoding="utf-8" ?>
     <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" enableLocalization="true">      
            <siteMapNode ur!="~/Default2.aspx" title="$resources:SiteMapLocalizations,str1" description=""/>
    </siteMap>

     <asp:Menu ID="MnuSideMenu" CellPadding="0" CellSpacing="0" runat="server" Width="100%">
        <DataBindings>
            <asp:MenuItemBinding DataMember="siteMapNode" NavigateUrlField="url" TextField="title" />
        </DataBindings>
    </asp:Menu>        

public partial class Default2 : System.Web.UI.Page
  {
protected void Page_Load(object sender, EventArgs e)
{
    XmlDataSource oXmlDataSource = new XmlDataSource();
    oXmlDataSource.XPath = "siteMap/siteMapNode";
    oXmlDataSource.DataFile = Server.MapPath("~") + @"/siteMap/x.sitemap";
    MnuSideMenu.DataSource = oXmlDataSource;
    MnuSideMenu.DataBind();
}
protected override void InitializeCulture()
{
    string languageId = "en-US";
    if (!string.IsNullOrEmpty(languageId))
    {
        if (languageId.EndsWith("FR")) languageId = "fr-FR";
        else languageId = "en-US";
        SetCulture(languageId);
    }

    if (Session["Language"] != null)
    {
        if (!Session["Language"].ToString().StartsWith(Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName)) SetCulture(Session["Language"].ToString());
    }

    base.InitializeCulture();
}

protected void SetCulture(string languageId)
{
    Session["Language"] = languageId;
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(languageId);
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(languageId);
}
protected void Button1_Click1(object sender, EventArgs e)
{

}

}

enter image description here


2 个答案:

答案 0 :(得分:0)

添加 Global.asax 文件写下这段代码

void Application_BeginRequest(Object sender, EventArgs e)
    {
        // Code that runs on application startup
        HttpCookie cookie = HttpContext.Current.Request.Cookies["CultureInfo"];
        if (cookie != null &amp;&amp; cookie.Value != null)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cookie.Value);
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cookie.Value);
        }
        else
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en");
        }
    }

了解详情Click

http://satindersinght.blogspot.in/2012/06/create-website-for-multilanguage.html


样本

 <siteMapNode url="EmployeeDetails.aspx " title="$resources:Resources,EmployeeDetails " description="$resources:Resources,Viewemployeedetails" />

注意:资源是指定链接中显示的主要根

答案 1 :(得分:0)

本地化不适用于XmlDataSource。所以我删除了XmlDataSource并使用了

        SiteMapDataSource  oSmapDataSource = new SiteMapDataSource();
        oSmapDataSource.SiteMapProvider= "siteMapCatalogueSiteMap";
        oSmapDataSource.ShowStartingNode = false; // Just a Dummy node as we dont have the Root node for Localisation concept
        (this.Master.FindControl("MnuSideMenu") as Menu).DataSource = oSmapDataSource;
        (this.Master.FindControl("MnuSideMenu") as Menu).DataBind();

现在印度尼西亚语言即将到来。