Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 多语言网站代码不起作用_C#_Asp.net_Multilingual_Globalization_Global Asax - Fatal编程技术网

C# 多语言网站代码不起作用

C# 多语言网站代码不起作用,c#,asp.net,multilingual,globalization,global-asax,C#,Asp.net,Multilingual,Globalization,Global Asax,我有一个网站,一直工作良好,直到我不得不删除一些不正确的资源文件。然而,这可能不是它不起作用的原因。基本上,与大多数多语言网站一样,用户可以通过单击标志更改语言: protected void imbEnglish_Click(object sender, ImageClickEventArgs e) { SetCultureStoreCookie("en-GB"); } protected void imbFrench_Click(object sender, ImageCli

我有一个网站,一直工作良好,直到我不得不删除一些不正确的资源文件。然而,这可能不是它不起作用的原因。基本上,与大多数多语言网站一样,用户可以通过单击标志更改语言:

    protected void imbEnglish_Click(object sender, ImageClickEventArgs e)
{
    SetCultureStoreCookie("en-GB");
}
protected void imbFrench_Click(object sender, ImageClickEventArgs e)
{
    SetCultureStoreCookie("fr-FR");
}
protected void imbGerman_Click(object sender, ImageClickEventArgs e)
{
    SetCultureStoreCookie("de-DE");
}
protected void imbSpanish_Click(object sender, ImageClickEventArgs e)
{
    SetCultureStoreCookie("es-ES");
}
protected void imbItalian_Click(object sender, ImageClickEventArgs e)
{
    SetCultureStoreCookie("it-IT");
}
protected void imbPolish_Click(object sender, ImageClickEventArgs e)
{
    SetCultureStoreCookie("fr-FR");
}

protected void SetCultureStoreCookie(string culture)
{
    //Sets the cookie that is to be used by Global.asax
    HttpCookie cookie = new HttpCookie("CultureInfo");
    cookie.Value = culture;
    Response.Cookies.Add(cookie);

    //Set the culture and reload the page for immediate effect. 
    //Future effects are handled by Global.asax

    Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);

    //Response.Redirect(Request.Path);
    Server.Transfer(Request.Path);
}
正如其在评论中所说,文化的后续设置在Global.asax中处理:

    protected void Application_BeginRequest(object sender, EventArgs e)
{
    HttpCookie cookie = Request.Cookies["CultureInfo"];

    if (cookie != null && cookie.Value != null)
    {
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(cookie.Value);
        Thread.CurrentThread.CurrentCulture = new CultureInfo(cookie.Value);
    }
    else
    {
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
        Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
    }
}
所有页面(包括母版页)都有英文默认资源文件,我已经开始创建法文资源文件:

然而,当你点击法国国旗时,一切都没有发生。我已经完成了代码,cookie正在设置中,Thread.CultureInfo行正在运行

还有什么地方可以查吗


谢谢。

我通过改变工作方式解决了这个问题。很明显,MasterPage类没有名为InitializeCulture的方法,使用我在其他文章中看到的一些技巧,我创建了一个基类页面:

using System;
public partial class AboutUs : BasePage
使用System.Collections.Generic; 使用System.Linq; 使用System.Web; 使用系统线程; 利用制度全球化

/// ///翻译摘要说明 /// 公共类基页:System.Web.UI.Page { 公共网页 { // //TODO:在此处添加构造函数逻辑 // }

}

然后将每个页面更改为从基类页面继承:

using System;
public partial class AboutUs : BasePage
{

}


这就解决了问题。

您是否使用“支持的区域性”编辑了.csproj?右键单击您的项目,卸载项目,右键单击,编辑.csproj,然后添加:恩,frHi Joffrey,它不是Visual Studio中的项目,它是一个简单的网站,但是正如我在介绍中所说的那样,翻译过去是有效的,没有.csproj文件。好的,在我的项目SL/WPF/Win8中,我需要在.csproj中添加受支持的文化以实现全球化。嗨,Joffrey,我很欣赏你所说的,但它从来没有。csproj和它曾经起过作用。此外,也没有在网站中添加.csproj文件的选项。