指定自定义资源文件为ASP.NET页/用户控件 [英] Specifying custom resource file for an ASP.NET page/usercontrol

查看:164
本文介绍了指定自定义资源文件为ASP.NET页/用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个名为Default.aspx页面,ASP.NET会自动使用App_LocalResources文件命名为Default.aspx.resx资源文件在页面定位服务器控件。

If I have a page called Default.aspx, ASP.NET automatically uses the resource file named Default.aspx.resx in App_LocalResources for localizing server controls in the page.

但由于某些原因,我需要选择另一个文件,假设默认-Custom.aspx.resx。为了提供一些背景,我已经为Default.aspx.resx但有些用户需要显示他们不同的内容,而我打算把在默认-Custom.aspx.resx。

But for some reason, I need to choose another file, let's say Default-Custom.aspx.resx. To provide some background, I already have Default.aspx.resx but some users need to have different content shown to them, which I am going to put in Default-Custom.aspx.resx.

时可以选择用于ASP.NET一个TemplateControl资源文件(简称编写定制ResourceProvider的)??

Is is possible to choose the Resource file used for a TemplateControl in ASP.NET (short of writing a custom ResourceProvider)??

推荐答案

在这里看看:

<一个href=\"http://www.west-wind.com/$p$psentations/wwdbresourceprovider/#Creating_a_custom_Resource_Provider\"相对=nofollow> ResourceManager.GetResourceFileName方法

此方法使用的CultureInfo的名称
  属性作为文件名的一部分
  比不变以外的所有文化
  文化。此方法不看在
  程序集的清单或触摸
  盘,并且只用于构造
  什么是资源文件名(适合
  以传递给ResourceReader
  构造函数)或清单资源
  BLOB名称应该的。

This method uses CultureInfo 's Name property as part of the file name for all cultures other than the invariant culture. This method does not look in an assembly's manifest or touch the disk, and is used only to construct what a resource file name (suitable for passing to the ResourceReader constructor) or a manifest resource blob name should be.

一个派生类可以重写此
  方法来寻找一个不同的
  扩展名,如的.resx,或一个
  命名完全不同的方案
  文件。

A derived class can override this method to look for a different extension, such as ".ResX", or a completely different scheme for naming files.

您可以尝试这样的事情:

You can try something like this:

public class ResxResourceManager : ResourceManager
{  
    protected override string GetResourceFileName(
         System.Globalization.CultureInfo culture)
    {
        return base.GetResourceFileName(culture);       
    }

    public string GetResxFileName(System.Globalization.CultureInfo culture)
    {
        return GetResourceFileName(culture).Replace(".resources", ".resx");
    }
}

有关这方面的:

<一个href=\"http://www.west-wind.com/$p$psentations/wwdbresourceprovider/#Creating_a_custom_Resource_Provider\"相对=nofollow>创建自定义资源提供商

下BuildManager和资源处理胡德

这篇关于指定自定义资源文件为ASP.NET页/用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆