【问题标题】:How do you read a local resource from a web method?如何从 Web 方法中读取本地资源?
【发布时间】:2014-04-10 01:14:56
【问题描述】:

我的项目结构如下:

我的 Web 方法在文件“MobileStart.cs”中声明,我需要从文件“start.aspx.resx”中读取资源值。以下是我读取资源值的尝试:

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static string EmailSurveyLink(string email)
    {
        var response = new StartPageResponse();

        string message = String.Format(HttpContext.GetLocalResourceObject("~/Surveys/start.aspx.resx", "LoginSentEmail", new CultureInfo("en-AU")).ToString(), messageVars);

        return new JavaScriptSerializer().Serialize(response);
    }

当我从客户端调用该方法时出现以下错误:

Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "start.aspx.resx.resources" was correctly embedded or linked into assembly "App_LocalResources.surveys.cdcab7d2.jsl8asuu" at compile time, or that all the satellite assemblies required are loadable and fully signed.

感谢您的解决方案。

【问题讨论】:

  • @Jumpei 试过了,但我得到了和上面一样的错误
  • 你需要转换文化吗?
  • 即使我使用以下内容,我也会收到相同的错误: string message = String.Format(HttpContext.GetLocalResourceObject("~/Surveys/start.aspx.resx", "LoginSentEmail").ToString( ), 消息变量);
  • 如果EmailSurveyLinkMobileStart 类的成员。 string message = String.Format(this.GetLocalResourceObject("LoginSentEmail").ToString(), messageVars);
  • 资源不是在编译时静态输入的吗?你不能直接引用资源字符串吗? Resources.LoginSentEmail

标签: c# asp.net webmethod


【解决方案1】:

您不能使用 HttpContext.GetLocalResourceObject 代替那个使用 HttpContext.GetGlobalResourceObject

这个问题之前已经在这里回答过:

Asp.Net localization of text in webservice method

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-10
    • 1970-01-01
    • 2013-03-21
    • 2014-06-07
    • 2012-11-25
    相关资源
    最近更新 更多