C# 如何从web方法读取本地资源?
我有以下项目结构: 我的web方法在文件“MobileStart.cs”中声明,我需要从文件“start.aspx.resx”中读取资源值。以下是我读取资源值的尝试:C# 如何从web方法读取本地资源?,c#,asp.net,webmethod,C#,Asp.net,Webmethod,我有以下项目结构: 我的web方法在文件“MobileStart.cs”中声明,我需要从文件“start.aspx.resx”中读取资源值。以下是我读取资源值的尝试: [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public static string EmailSurveyLink(string email) { var response = new StartPag
[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.
我希望能找到解决方案,谢谢
您不能使用HttpContext.GetLocalResourceObject
代替该用法
HttpContext.GetGlobalResourceObject
问题已在此处得到解答:
@Jumpei尝试过,但我遇到了与上述相同的错误您需要切换区域性吗?即使我使用以下命令,我也会遇到相同的错误:string message=string.Format(HttpContext.GetLocalResourceObject(“~/Surveys/start.aspx.resx”,“LoginSentEmail”).ToString(),messageVars);如果
EmailSurveyLink
是类MobileStart
的成员string message=string.Format(this.GetLocalResourceObject(“LoginSentEmail”).ToString(),messageVars)代码>资源在编译时是否不是静态类型?你不能直接引用资源字符串吗?Resources.LoginSentEmail