Reputation: 560
I have just started to learn asp.net MVC3 and i run into this problem:
I'm using visual studio 2010, and there were no Errors during build, only when i try to run application. I'm searching for an answer on Google but with no success. Does anybody knows how to fix this?
Thanks!
EDIT-ContextModule code:
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);
}
}
}
}
Upvotes: 1
Views: 660
Reputation: 2733
It seems like you have attached a HTTP module that cannot be found. How have you created the project? The module can be removed in web.config.
EDIT
You need to change:
<httpModules>
<add name="ContextModule" type="testbaza.ContextModule, testbaza" />
</httpModules>
to
<httpModules>
<add name="ContextModule" type="testbaza.Models.ContextModule, testbaza" />
</httpModules>
Notice the changed namespace.
Upvotes: 2
Reputation: 3139
I believe you should remove the , testbaza
part from your add
tag.
<configuration>
<system.web>
<httpModules>
<add name="MyModule" type="MyModule" />
</httpModules>
</system.web>
</configuration>
Upvotes: 2