gpt4 book ai didi

asp.net - 为 ASP.NET 页/用户控件指定自定义资源文件

转载 作者:行者123 更新时间:2023-12-01 04:11:51 24 4
gpt4 key购买 nike

如果我有一个名为 Default.aspx 的页面,ASP.NET 会自动使用 App_LocalResources 中名为 Default.aspx.resx 的资源文件来本地化页面中的服务器控件。

但出于某种原因,我需要选择另一个文件,比如说 Default-Custom.aspx.resx。为了提供一些背景信息,我已经有了 Default.aspx.resx,但有些用户需要向他们显示不同的内容,我将把这些内容放在 Default-Custom.aspx.resx 中。

是否可以在 ASP.NET 中选择用于 TemplateControl 的资源文件(缺少编写自定义 ResourceProvider)??

最佳答案

看看这里:

ResourceManager.GetResourceFileName Method

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.

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



你可以尝试这样的事情:
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");
}
}

有关更多信息:

Creating a custom Resource Provider

Under the Hood of BuildManager and Resource Handling

关于asp.net - 为 ASP.NET 页/用户控件指定自定义资源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5583529/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com