Search code examples
c#asp.netstaticlocalizationwebmethod

How to Use LocalResourceObject in static methods [webmethod]


I can simply use localisation in aspx page but cannot use in aspx.cs files.

 [WebMethod]
    public static string Menu(int role, int driver)
    {
 string _permissions = dr["FN_2"].ToString().Replace(" /V*", System.Web.HttpContext.GetLocalResourceObject("CRL.aspx", "RV.Text").ToString());
// This way didn't get error in coding but when I run it, give me no permission error for virtual path

string _permissions = dr["FN_2"].ToString().Replace(" /V*", System.Web.HttpContext.GetLocalResourceObject("RV.Text").ToString());
//I cannot use in this way
    }

In aspx page, I can call it GetLocalResourceObject("RV.Text") like this. I have to get reach these localisation stuff, I need them for a lot things.

I cannot return text from localresource object in these two ways. One of them get error while coding, other one cannot reach the virtual path due to permission. How can I use GetLocalResourceObject in [WebMethod]?


Solution

  • You can try static string:

    public static string _RV { get; set; }
    

    then you fill it where you want eg. Page_Load:

    _RV = GetLocalResourceObject("RV.Text").ToString();
    

    and then you can run it well:

        [WebMethod]
        public static string Menu(int role, int driver)
        {
         string _permissions = dr["FN_2"].ToString().Replace(" /V*", _RV);    
        }
    

    I hope it works :)