2012-09-22 2 views
1

유형 "ContextModule"을로드하고 나는이 문제로 실행 할 수 없습니다 :이파서 오류 메시지 : 난 그냥 asp.net의 MVC3를 배우기 시작했다

error message

내가 비주얼 스튜디오 2010을 사용하고, 그리고 빌드 도중 오류가 발생하지 않았을 때만 애플리케이션을 실행하려고했습니다. Google에서 답변을 찾고 있는데 성공하지 못했습니다. 누구든지이 문제를 해결하는 방법을 알고 있습니까?

감사합니다.

EDIT-ContextModule 코드 :

using System; 
using System.Web; 

namespace testbaza.Models 
{ 
    public class ContextModule : IHttpModule 
    { 

     internal const string CONTEXT_KEY = "datacontext"; 

     public void Dispose() 
     { 

     } 

     public void Init(HttpApplication context) 
     { 
      context.PostRequestHandlerExecute += new EventHandler(context_PostRequestHandlerExecute); 
      context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute); 
     } 

     private void context_PreRequestHandlerExecute(object sender, EventArgs e) 
     { 
      if (HttpContext.Current.Session != null) 
      { 
       HttpContext.Current.Session[CONTEXT_KEY] = new EntitiesModel(); 
      } 
     } 

     private void context_PostRequestHandlerExecute(object sender, EventArgs e) 
     { 
      CommitTransactions(); 

      DisposeContext(); 

      ClearSession(); 

     } 

     private void CommitTransactions() 
     { 
      if (HttpContext.Current.Session == null) 
      { 
       return; 
      } 

      EntitiesModel dbContext = 
       HttpContext.Current.Session[CONTEXT_KEY] as EntitiesModel; 
      if (dbContext != null) 
      { 

       dbContext.SaveChanges(); 
      } 
     } 

     private void DisposeContext() 
     { 
      if (HttpContext.Current.Session == null) 
      { 
       return; 
      } 

      EntitiesModel dbContext = 
       HttpContext.Current.Session[CONTEXT_KEY] as EntitiesModel; 
      if (dbContext != null) 
      { 

       dbContext.Dispose(); 
      } 
     } 

     private void ClearSession() 
     { 

      if (HttpContext.Current.Session == null) 
      { 
       HttpContext.Current.Session.Remove(CONTEXT_KEY); 
      } 
     } 
    } 
} 

답변

2

찾을 수없는 HTTP 모듈이 연결되어있는 것 같습니다. 프로젝트를 어떻게 만들었습니까? web.config에서 모듈을 제거 할 수 있습니다.

<httpModules> 
    <add name="ContextModule" type="testbaza.ContextModule, testbaza" /> 
</httpModules> 

변경된 네임 스페이스 공지 사항

<httpModules> 
    <add name="ContextModule" type="testbaza.Models.ContextModule, testbaza" /> 
</httpModules> 

에 :

편집
당신은 변경해야합니다.

+0

이 비디오에 표시된대로 모듈과 프로젝트를 만들었습니다. http://tv.telerik.com/watch/orm/building-a-mvc-3-application-database-first-with-openaccess-creating-model – user1598696

+1

@ user1598696 ContextModule의 소스 코드를 게시 할 수 있습니까? 네임 스페이스 등을 확인할 수 있습니까? – Xharze

+0

편집에 내 코드를 게시했습니다. 도움을 주셔서 감사합니다. – user1598696

2

나는 당신이 당신의 add 태그에서 , testbaza 부분을 제거해야합니다 생각합니다.

<configuration> 
    <system.web> 
     <httpModules> 
      <add name="MyModule" type="MyModule" /> 
     </httpModules> 
    </system.web> 
</configuration> 
+0

나는 그것을 시도했다, 그것은 도움이되지 않았다. .. 다른 어떤 생각? – user1598696

관련 문제