【问题标题】:IHttpModule not being invoked未调用 IHttpModule
【发布时间】:2014-01-18 02:40:08
【问题描述】:

在我的程序中,我需要检查每个请求,如果 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>

【问题讨论】:

    标签: c# asp.net .net


    【解决方案1】:

    试试这个,对我有用。

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-03
      • 2010-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-11
      • 2011-01-25
      • 1970-01-01
      相关资源
      最近更新 更多