相对虚拟路径“x.resx”这里不允许

发布于 2024-10-07 01:14:45 字数 2307 浏览 4 评论 0原文

目前,我们正在尝试本地化我们相当广泛的模块,并且使用单个 resx (为了便于管理),我们编写了以下代码,该代码确实返回键,但它确实在事件查看器中给我们留下了一条日志消息(在代码)

我还应该添加我不能使用httpcontext.current.server.mappath,因为这些函数也在没有httpcontext的地方使用

代码:

Public Shared Function GetString(ByVal key As String, ByVal ParamArray params As String()) As String
            Dim SharedResourceFolder As String = "~/App_GlobalResources/"
            Dim myStr As String = Nothing
            If CultureInfo.CurrentCulture.Name <> "en-GB" Then
                myStr = Localization.GetString(key, SharedResourceFolder & "Resources." & CultureInfo.CurrentCulture.Name & ".resx")
                If myStr Is Nothing OrElse myStr = "" Then
                    myStr = Localization.GetString(key, SharedResourceFolder & "Resources." & CultureInfo.CurrentCulture.Name.Substring(0, 2) & ".resx")
                End If
            End If

            If myStr Is Nothing OrElse myStr = "" Then
                myStr = Localization.GetString(key, SharedResourceFolder & "Resources.resx")
            End If

            If myStr IsNot Nothing AndAlso myStr <> "" Then
                Return String.Format(CultureInfo.CurrentCulture, myStr, params)
            End If
            Dim res As String = Localization.GetString(key, "Resources.resx", "en-GB")
            If String.IsNullOrEmpty(res) Then
               Return Nothing
            End If
            Return String.Format(CultureInfo.InvariantCulture, res, params)
        End Function

错误消息:

System.ArgumentException:相对的 虚拟路径“sharedresources.resx”是 这里不允许。在 System.Web.VirtualPath.FailIfRelativePath() 在 System.Web.Hosting.HostingEnvironment.MapPathActual(虚拟路径 virtualPath, 布尔允许Null) at System.Web.Hosting.HostingEnvironment.MapPathInternal(虚拟路径 虚拟路径)位于 System.Web.Hosting.HostingEnvironment.MapPath(虚拟路径 虚拟路径)位于 System.Web.Hosting.HostingEnvironment.MapPath(字符串 虚拟路径)位于 DotNetNuke.Services.Localization.Localization.GetResourceFileCallBack(CacheItemArgs 缓存项参数)位于 DotNetNuke.Common.Utilities.DataCache.GetCachedData[TObject](CacheItemArgs 缓存项参数, 缓存项过期回调 缓存项已过期,布尔值 存储在字典中)

感谢任何帮助


更新:

更改为物理路径导致 DNN 核心内出现问题,恢复为虚拟路径并更改模块中其他位置的一行代码修复了问题

Currently we are trying to localise our rather extensive module, and what use a single resx (for ease of management), WE have written the following code which does return keys however it does leave us with a log message in the event viewer (below the code)

I should also add I cannot use httpcontext.current.server.mappath, as the functions are also used where there is not a httpcontext

Code:

Public Shared Function GetString(ByVal key As String, ByVal ParamArray params As String()) As String
            Dim SharedResourceFolder As String = "~/App_GlobalResources/"
            Dim myStr As String = Nothing
            If CultureInfo.CurrentCulture.Name <> "en-GB" Then
                myStr = Localization.GetString(key, SharedResourceFolder & "Resources." & CultureInfo.CurrentCulture.Name & ".resx")
                If myStr Is Nothing OrElse myStr = "" Then
                    myStr = Localization.GetString(key, SharedResourceFolder & "Resources." & CultureInfo.CurrentCulture.Name.Substring(0, 2) & ".resx")
                End If
            End If

            If myStr Is Nothing OrElse myStr = "" Then
                myStr = Localization.GetString(key, SharedResourceFolder & "Resources.resx")
            End If

            If myStr IsNot Nothing AndAlso myStr <> "" Then
                Return String.Format(CultureInfo.CurrentCulture, myStr, params)
            End If
            Dim res As String = Localization.GetString(key, "Resources.resx", "en-GB")
            If String.IsNullOrEmpty(res) Then
               Return Nothing
            End If
            Return String.Format(CultureInfo.InvariantCulture, res, params)
        End Function

Error Message:

System.ArgumentException: The relative
virtual path 'sharedresources.resx' is
not allowed here. at
System.Web.VirtualPath.FailIfRelativePath()
at
System.Web.Hosting.HostingEnvironment.MapPathActual(VirtualPath
virtualPath, Boolean permitNull) at
System.Web.Hosting.HostingEnvironment.MapPathInternal(VirtualPath
virtualPath) at
System.Web.Hosting.HostingEnvironment.MapPath(VirtualPath
virtualPath) at
System.Web.Hosting.HostingEnvironment.MapPath(String
virtualPath) at
DotNetNuke.Services.Localization.Localization.GetResourceFileCallBack(CacheItemArgs
cacheItemArgs) at
DotNetNuke.Common.Utilities.DataCache.GetCachedData[TObject](CacheItemArgs
cacheItemArgs,
CacheItemExpiredCallback
cacheItemExpired, Boolean
storeInDictionary)

Thankful for any help


UPDATE:

Changing to a physical path caused me an issue within the DNN core, reverting back to a virtual path and changing a line of code else where in the module Fixed the issue

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苄①跕圉湢 2024-10-14 01:14:45

我的猜测是您正在使用根相对路径,由于您位于 HTTP 上下文之外,因此系统会失败。这是基于提供的堆栈跟踪和对“FailIfRelativePath()”方法的调用。

如果您查看 Localization.GetString 的 DotNetNuke 代码,通常会提供物理文件路径而不是相对路径。要确认这一点,请查看从 PortalModuleBase 继承的任何模块控件上可用的 LocalResourceFile 属性。

My guess here is that you are using a root relative path, which since you are outside of an HTTP Context the system is failing. This is based on the stack trace provided and the call to "FailIfRelativePath()" method.

If you look at the DotNetNuke code for Localization.GetString, typically it is provided a physical file path and not a relative path. To confirm this look at the LocalResourceFile property that is available on any module control that inherits from PortalModuleBase.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文