2011-02-10 3 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 클래스를 사용해 보았지만 동일한 예외가 발생합니다.

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

결코 마음을 따를

내 위해 Application_Start 보인다. 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 
    } 
관련 문제