目前我们正在尝试本地化我们相当广泛的模块,以及使用单个 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 virtualPath, Boolean permitNull) 在 System.Web.Hosting.HostingEnvironment.MapPathInternal(VirtualPath virtualPath) 在 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)
感谢您的帮助
更新:
更改为物理路径导致我在 DNN 核心中出现问题,恢复为虚拟路径并更改模块中其他位置的代码行 修复了问题