2016-05-10 13 views
0

C#でSessionを使わずにBメソッドからAメソッドにデータを取得しますか?私は<code>C#</code>で<code>session</code>を使用せずに<b>get_data</b>方法に私の<b>master_handler</b><code>method</code> handler_responseデータを取得できますか

現在、私はセッションを使用してデータを取得し、私はsessionを使用せずにGET_DATA()メソッドの下文字列応答handler_responseデータを取得したいです。

これを行うことができますどのように

私のコードは

[WebMethod] 
public static string GET_DATA() 
{ 
    string Search = "1"; 
    master_handler(Search); 

    string response = string.Empty; 
    response = (string)HttpContext.Current.Session["HANDLER_RESPONSE"]; // getting handler_response here 
    HttpContext.Current.Session["obj_GET_FLIGHT_DATA"] = response; 
    return response; 
} 

public static string master_handler(string dt) 
{ 
    string handler_response= string.Empty; 
    LibraryCaller.Master_Handler MH = new LibraryCaller.Master_Handler(); 
    string get_api_data = MH.Search(dt); 
    JObject jObj = JObject.Parse(get_api_data); 
    handler_response= jObj.ToString(); 
    HttpContext.Current.Session["HANDLER_RESPONSE"] = handler_response; // here currently using sesson 
    return handler_response; 
} 
+0

あなたは値をキャッシュし、そこ –

答えて

0

キャッシュの代わりに値です助けてください。

Cache.Insert("HANDLER_RESPONSE", handler_response); 

使用し、それを取得するには:

string handler_response; 
handler_response = (string)Cache["HANDLER_RESPONSE"]; 

です最も簡単な方法それはキャッシュを介して、それ以上のことをtheresとしてそれを読んでください。

0

私はこれをクラスを使用して行っています。

public class handler 
{ 
    public string data_handler(string dt) 
    { 
     string handler_response= string.Empty; 
     LibraryCaller.Master_Handler MH = new LibraryCaller.Master_Handler(); 
     string get_api_data = MH.Search(dt); 
     JObject jObj = JObject.Parse(get_api_data); 
     handler_response= jObj.ToString(); 
     HttpContext.Current.Session["HANDLER_RESPONSE"] = handler_response; // here currently using sesson 
     return handler_response; 
    } 
} 

とアクセスデータ

handler h = new handler(); 
    response = h.data_handler(search); 
+0

からそれを取り出すことができることは、クラスを作成するための唯一の理由だ場合はやり過ぎ私には思えます。 –

関連する問題

 関連する問題