Can anyone tell me how can i dynamically initialize thread culture in a asp.net webservice call?
In my aspx pages i have a base page where i override the InitializeCulture() Method.
Note that the value of selected language is saved in Session State.
In Global.asax
file you can set the current culture, even if its web service or web page.
// 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);
}
}
You are changing your requirements, however Session
object will not be available in Begin_Request
method, you can do this in your web method.
[WebMethod]
public static string MyWebMethod()
{
String culture = Session["MyCurrentCulutre"] as String;
System.Threading.Thread.CurrentThread.CurrentCulture =
System.Globalization.CultureInfo.CreateSpecificCulture(culture);
return "My results";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With