Asp.net mvc 2 MVCSiteMapProvider的资源文件

Asp.net mvc 2 MVCSiteMapProvider的资源文件,asp.net-mvc-2,sitemap,mvcsitemapprovider,Asp.net Mvc 2,Sitemap,Mvcsitemapprovider,我正在使用MVCSiteMapProvider为我的应用程序生成带有本地化的菜单。只要菜单的资源文件在App_GlobalResources文件夹中,我的程序就可以正常工作。当我将资源移动到另一个文件夹中时,会出现无法找到资源的错误。 我正在使用$resources:Resource,menu\u Home访问MVC.sitemap文件中的资源。 我希望将资源文件保存在自定义文件夹中,而不将其存储在App_GlobalResources文件夹中。有人能帮忙吗 发生这种情况是因为MvcSiteMa

我正在使用MVCSiteMapProvider为我的应用程序生成带有本地化的菜单。只要菜单的资源文件在App_GlobalResources文件夹中,我的程序就可以正常工作。当我将资源移动到另一个文件夹中时,会出现无法找到资源的错误。 我正在使用
$resources:Resource,menu\u Home
访问MVC.sitemap文件中的资源。
我希望将资源文件保存在自定义文件夹中,而不将其存储在App_GlobalResources文件夹中。有人能帮忙吗

发生这种情况是因为MvcSiteMapNode.Title属性中的以下代码:

var implicitResourceString = GetImplicitResourceString("title");
if (implicitResourceString != null && implicitResourceString == this["title"])
{
    return implicitResourceString;
}
implicitResourceString = GetExplicitResourceString("title", this["title"], true);
if (implicitResourceString != null && implicitResourceString == this["title"])
{
    return implicitResourceString;
}
在GetExplicitResourceString()方法中,最后一个参数为true,这意味着throwIfNotFound。这就是抛出异常的原因。我通过将上面的代码替换为以下代码来修复它:

if (!string.IsNullOrEmpty(title))
{
    if (Provider.EnableLocalization)
    {
        try
        {
            if (!string.IsNullOrEmpty(title) && title.Contains("."))
            {
                int idx = title.LastIndexOf(",");
                string res = title.Substring(0, idx);
                string assembly = title.Substring(idx + 1);

                idx = res.LastIndexOf(".");
                string type = res.Substring(0, idx);
                string key = res.Substring(idx + 1);
                var rm = new ResourceManager(type, Assembly.Load(assembly));
                return rm.GetString(key);
            }
        }
        catch
        {
        }
        return title;
    }
}

并在.sitemap文件内部,而不是title=“$resources:Resource,Key”语法使用title=“Namespace.Class.Property,Assembly”语法,这在将嵌入式资源与强类型生成的类一起使用时更为合适。

发生这种情况是因为MVCSItemaNode.title属性中的以下代码:

var implicitResourceString = GetImplicitResourceString("title");
if (implicitResourceString != null && implicitResourceString == this["title"])
{
    return implicitResourceString;
}
implicitResourceString = GetExplicitResourceString("title", this["title"], true);
if (implicitResourceString != null && implicitResourceString == this["title"])
{
    return implicitResourceString;
}
在GetExplicitResourceString()方法中,最后一个参数为true,这意味着throwIfNotFound。这就是抛出异常的原因。我通过将上面的代码替换为以下代码来修复它:

if (!string.IsNullOrEmpty(title))
{
    if (Provider.EnableLocalization)
    {
        try
        {
            if (!string.IsNullOrEmpty(title) && title.Contains("."))
            {
                int idx = title.LastIndexOf(",");
                string res = title.Substring(0, idx);
                string assembly = title.Substring(idx + 1);

                idx = res.LastIndexOf(".");
                string type = res.Substring(0, idx);
                string key = res.Substring(idx + 1);
                var rm = new ResourceManager(type, Assembly.Load(assembly));
                return rm.GetString(key);
            }
        }
        catch
        {
        }
        return title;
    }
}

在.sitemap文件内部,而不是title=“$resources:Resource,Key”语法使用title=“Namespace.Class.Property,Assembly”语法,这在将嵌入式资源与强类型生成的类一起使用时更合适。

我认为这是不可能的,由于这是使用.NET framework中XmlSiteMapProvider内置的默认本地化功能完成的,请参阅。但是如果可以改变的话,那就行了。我到处都找过了。。。好像是这样-/我也有同样的问题。我无法理解为什么它没有被解决,因为MVC应用程序中的资源最好放在其他地方,而在App_GlobalResources中,出于测试目的。我认为这是不可能做到的,因为这是使用.NET framework中XmlSiteMapProvider内置的默认本地化功能来实现的,请参阅。但是如果可以改变的话,那就行了。我到处都找过了。。。好像是这样-/我也有同样的问题。我无法理解为什么它没有被解决,因为MVC应用程序中的资源更好地放在其他地方,而是放在App_GlobalResources中,用于测试目的。