如何在ASP.NET WebService调用中动态初始化文化?
发布时间:2020-12-16 03:26:38 所属栏目:asp.Net 来源:网络整理
导读:任何人都可以告诉我如何在asp.net webservice调用中动态初始化线程文化? 在我的aspx页面中,我有一个基页,我重写了InitializeCulture()方法. 请注意,所选语言的值保存在会话状态中. 解决方法 在Global.asax文件中,您可以设置当前文化,即使其Web服务或网页也
任何人都可以告诉我如何在asp.net webservice调用中动态初始化线程文化?
在我的aspx页面中,我有一个基页,我重写了InitializeCulture()方法. 请注意,所选语言的值保存在会话状态中. 解决方法
在Global.asax文件中,您可以设置当前文化,即使其Web服务或网页也是如此.
// 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); } } 您正在更改您的要求,但是在Begin_Request方法中无法使用Session对象,您可以在Web方法中执行此操作. [WebMethod] public static string MyWebMethod() { String culture = Session["MyCurrentCulutre"] as String; System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(culture); return "My results"; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net部署到IIS常见问题的解决方法
- asp.net-mvc-2 – 未针对请求的URL配置默认文档,并且未在服
- 多终端数据同步机制设计(一)
- asp.net-mvc-3 – EF 4.1 Code First多个多对多关系
- asp.net – .NET Core项目添加对.NET Framework项目的引用.
- mvc-mini-profiler – MVC MiniProfiler与ASP.NET MVC 4
- asp.net-mvc – .NET MVC:计算Web应用程序中的Action方法
- ASP.NET AJAX工具包 – CalendarExtender在Postback上重置
- asp.net-mvc – Mvc Mini Profiler请求带有和不带有RouteBa
- asp.net – 使用ClientId和ClientSecret进行Web API授权