2011-02-10 16 views
0

ASP.Net MVC 3.0でAutofac 2.4.4を使用してhttp://code.google.com/p/autofac/wiki/MultitenantIntegrationバージョン2.4.4を使用しています。Autofac Contrib Multi Tenantが「このコンテキストではリクエストを利用できません」という例外をスローする

新しいAsp.Net MVC 3サポート(AutofacDependencyResolverを使用)を使用します。テナント識別戦略クラス(ITenantIdentificationStrategyの実装)が「このコンテキストではリクエストを利用できません」という例外が発生するという問題が発生しました。

私はAutofacContrib.Multitenant.Web.RequestParameterTenantIdentificationStrategyクラスを使用しようとしましたが、同じ例外がスローされます。

私のApplication_Startは

protected void Application_Start() 
{ 
    //wire up all the necessary objects used in this web application 
    IContainer container = BootStrap.RegisterAll().Build(); 

    //multi tenant support 
    MultitenantContainer multiTenant = new MultiTenancy().Register(container); 


    DependencyResolver.SetResolver(new AutofacDependencyResolver(multiTenant.BeginLifetimeScope())); 

} 

答えて

2

は気にしないで続くように見えます。 HttpContext.Current.Requestは、IIS 7.0のApplication_Startでは使用できません。唯一の解決策は、HTTPExceptionを取得し、CatchでTenantIdをnullに設定してfalseを返すことです。

public bool TryIdentifyTenant(out object tenantId) 
    { 
     var current = HttpContext.Current; 

     try 
     { 
      if (current == null) 
      { 
       tenantId = null; 
       return false; 
      } 

      var request = current.Request; 
     } 
     catch (HttpException) 
     { 
      tenantId = null; 
      return false; 
     } 

     //continue with your tenant identification 
    } 
関連する問題