2011-10-25 5 views

答えて

4

Global.asaxファイルでは、ウェブサービスまたはウェブページがある場合でも、現在のカルチャーを設定できます。

// PreRequestHandlerExecute occurs after initialization of Session 
void Application_PreRequestHandlerExecute(Object Sender, EventArgs e) 
{ 
    // check if session is required for the request 
    // as .css don't require session and accessing session will throw exception 
    if (Context.Handler is IRequiresSessionState 
     || Context.Handler is IReadOnlySessionState) 
    { 
     string culture = "en-US"; 
     if (Session["MyCurrentCulutre"] != null) 
     { 
      culture = Session["MyCurrentCulutre"] as String; 
     } 

     System.Threading.Thread.CurrentThread.CurrentCulture = 
      System.Globalization.CultureInfo.CreateSpecificCulture(culture); 
    } 
} 

あなたの要件を変更している、しかしSessionオブジェクトは、あなたのWebメソッドでこれを行うことができ、Begin_Request方法では使用できません。

[WebMethod] 
public static string MyWebMethod() 
{ 
    String culture = Session["MyCurrentCulutre"] as String; 

    System.Threading.Thread.CurrentThread.CurrentCulture = 
     System.Globalization.CultureInfo.CreateSpecificCulture(culture); 

    return "My results"; 
} 
+0

InitializeCulture()は、System.Web.Services.WebServiceメソッドではなくページメソッドです。 – rtcardoso

+1

@Waqas Raja、あなたは本当の人生から自由なexmpleを与えることができますか?イスラエルのイムは私たちの中にあると言うことができます...あなたは例を挙げることができますか? –

+0

セッションで優先ユーザー言語を保存するとします。その後、私のjavascriptはwebservice呼び出しを行います。応答で私はユーザーの好みの言語でユーザーメッセージを送信したい... – rtcardoso

関連する問題