在我的程序中,我需要检查每个请求,如果url中有language
参数需要获取它并保存在会话中。这是我的代码。在VS 2010开发服务器中一切正常。但是当我尝试在IIS 7中进行调试时,public void Init(HttpApplication context)
方法无法调用。任何想法?
Globalizer.cs
using System;
using System.Web;
using System.Threading;
public class Globalizer : IHttpModule
{
public void Init(HttpApplication context)
{
context.AcquireRequestState += new EventHandler(setLanguage);
}
public void Dispose(){}
public void setLanguage(Object sender, EventArgs i_eventArgs)
{
HttpApplication http_application = sender as HttpApplication;
string language = http_application.Request.Params["language"];
if (language == "en" || language == "ja" || language == "zh" || language == "th")
{
http_application.Session["language"] = language;
}
else
{
language = (string)http_application.Session["language"];
}
var l_culture = new System.Globalization.CultureInfo(language);
Thread.CurrentThread.CurrentCulture = l_culture;
Thread.CurrentThread.CurrentUICulture = l_culture;
}
}
的Web.config
<configuration>
<system.web>
<globalization uiCulture="auto" culture="auto" enableClientBasedCulture="true"/>
<httpModules>
<add name="LanguageSettingModule" type="Globalizer, App_Code" />
</httpModules>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
答案 0 :(得分:0)
试试这个,为我工作。
<configuration>
<system.web>
<globalization uiCulture="auto" culture="auto" enableClientBasedCulture="true"/>
<httpModules>
<add name="Globalizer" type="Globalizer" />
</httpModules>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name = "Globalizer" type="Globalizer"/>
</modules>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>