DNN编译后找不到资源文件

DNN编译后找不到资源文件,大概要改一下程序才能用,下面是找的代码片断,有这方面经验的好手们,方便的话就指点下,谢谢

////////////////////////////
 ASP.NET操作资源文件

转自:http://tb.blog.csdn.net/TrackBack.aspx?PostId=1653141

在上次的一个国际化项目中用到资源文件,在.NET中对资源文件的访问很多人遇到过同样的麻烦,在这里跟大家共享一种方法,希望能对初学者有所帮助.

   private string GetGlobalResourceString(string className, string resourceKey)
    {
        Type type = GetResourceType(className);
        return type.GetProperty(resourceKey).GetValue(null, null) as string;
    }

    private Type GetResourceType(string name)
    {
        return (Assembly.Load("App_GlobalResources")).GetType("Resources." + name);
    }

//在Page_Load中将值打印出来
//资源文件名为:john.strings.resx
//中有key : john    value : xizhaohui
//程序运行将在页面打印 "xizhaohui"
  protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(GetGlobalResourceString("john.strings", "john"));
    }

 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1653141

转自:http://tb.blog.csdn.net/TrackBack.aspx?PostId=1653141

///////////////////////

asp.net2.0读取资源文件的方式整理


方法一
System.Web.HttpContext.GetGlobalResourceObject("Resource", "Name").ToString()

 
方法二

   private string GetGlobalResourceString(string className, string resourceKey)
    {
        Type type = GetResourceType(className);
        //type.GetProperty("Culture").SetValue(null, new CultureInfo("zh-cn"), null);

        return type.GetProperty(resourceKey).GetValue(null, null) as string;
    }
    private Type GetResourceType(string name)
    {
        Assembly ass = Assembly.Load("App_GlobalResources");
        Type type = ass.GetType("Resources." + name);
        return type;
    }

/////////////////////////////////

在ASP.net中有两个固定文件夹App_GlobalResources和App_LocalResources,其中App_GlobalResources会编译到App_GlobalResources.dll中,用于存放公用的资源,App_LocalResources不执行编译,用于存放各个页面自己的资源。在Page和UserControl的基类TemplateControl中新增了GetGlobalResourceObject和GetLocalResourceObject两个函数,可以在页面中直接调用(在HttpContext中也有两个同样的静态方法)以取得指定的资源。
        例如:在App_GlobalResources中有个test.strings.resx的资源文件,里面有条名为s的资源,则可以使用GetGlobalResourceObject("test.strings", "s")来取得它,这里没有指定取得何种语言的资源,这样的话将会使用Thread.CurrentThread.CurrentUICulture中的语言,自己也可以在使用之前设定Thread.CurrentThread.CurrentUICulture的值。可以没有test.strings.resx这个文件,直接使用test.strings.zh-cn.resx、test.strings.en-us.resx...等文件。
        还有很多方法可以取得资源,这里写出一个,不同的是必须有test.strings.resx这个文件。可以直接使用Resources.test.strings.s来取得资源,这样子做感觉不够灵活,可以模仿GetGlobalResourceObject方法写一个GetGlobalResourceString方法,如下:
    private string GetGlobalResourceString(string className, string resourceKey)
    {
        Type type = GetResourceType(className);
        //type.GetProperty("Culture").SetValue(null, new CultureInfo("zh-cn"), null);

        return type.GetProperty(resourceKey).GetValue(null, null) as string;
    }
    private Type GetResourceType(string name)
    {
        Assembly ass = Assembly.Load("App_GlobalResources");
        Type type = ass.GetType("Resources." + name);
        return type;
    }



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=624763


 

原文地址:https://www.cnblogs.com/shiningrise/p/800228.html