关于网友提出的“aspnet 请问一下在ASPNET里怎样使用资源文件?”问题疑问,本网通过在网上对“aspnet 请问一下在ASPNET里怎样使用资源文件?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题:aspnet 请问一下在ASPNET里怎样使用资源文件?描述:
请问在ASP.NET里面怎样解决国际化的问题?谁有代码给我一个,只需要实现一个简单功能:
有一个MSG.zh-cn.resx和MSG.en-us.resx
里面包含一个键值对:MSG.zh-cn.resx包含welcomeMsg:欢迎你!!
MSG.en-us.resx包含welcomeMsg:Wellcome!!
然后在Default.aspx里面通过2种方式显示出来,一种是直接在HTML代码中写出来,另一种是在Page_Load打印出来。
而且是根据浏览器的语言自动使用相应的资源文件。
有的请联系QQ:80820431
Email:80820431@qq.com
解决方案1:
帮顶+学习!
解决方案2:web.config配置
接着就是调用:
建一个App_GlobalResources目录用来放资源文件,资源文件的命名规则MSG.zh-CN.resx(简体中文)也就是操作系统中的语言类型
调用: <%=Resources.MSG.home %>home是对应资源里的名称
你也可以看下这个帖,问的问题和你差不多,http://topic.csdn.net/u/20090401/09/eb26df8f-629f-4c50-ba43-c90745295ab2.html 解决方案3:
App_GlobalResources是全局资源文件夹,加入添加了GlobalResource.resx资源
只要在源代码中使用Resources.GlobalResource.welcomeMsg就可以访问了
页面中用<%$ Resources:GlobalResource,welcomeMsg%>访问
帮顶
解决方案5: namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string lang = "en-us";
if (System.Web.HttpContext.Current.Request.UserLanguages != null)
{
lang = System.Web.HttpContext.Current.Request.UserLanguages[0];
}
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(lang);
if (ci.IsNeutralCulture)
ci = System.Globalization.CultureInfo.CreateSpecificCulture(ci.Name);
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Resources.ResourceManager rm = new System.Resources.ResourceManager("WebApplication1.MSG", typeof(WebApplication1.WebForm1).Assembly);
GlobalTest.Text = rm.GetString("welcomeMsg");
}
}
}