使用ASP.NET资源文件的HTTP处理程序

3

有没有办法访问存储在 App_LocalResource 或 App_GlobalResources 中的资源?我知道如何在 Web 表单页面中做到这一点,但无法弄清楚如何从 .ashx 文件中做到这一点...

3个回答

2

试试这个:

HttpContext.GetGlobalResourceObject

或者
HttpContext.GetLocalResourceObject

0
好的,在经过一段时间的调查后,我选择了以下的方法:
        Dictionary<string, string> resAttrs = new Dictionary<string, string>();

        ResXResourceReader rsxr = new ResXResourceReader(HttpContext.Current.Request.PhysicalApplicationPath + "Resource.resx");

        foreach (DictionaryEntry d in rsxr)
            resAttrs.Add(d.Key.ToString(), d.Value.ToString());

然后通过resAttrs字典访问资源。也许这不是最好的方法,但对我来说有效。


0

从IHttpHandler实现中无法使用GetLocalResourceObject。 - Mr. Pumpkin
谢谢Alex的评论,我已经添加到帖子中。 - Aghilas Yakoub

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接