Custom Controller, not working with areas

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Custom Controller, not working with areas



I have a custom controller in my project because I use Structure Map as an IOC Container. When I add Datatables.mvc (library for jquery grid), and call a view from areas, the custom Controller does not work at runtime and gives me an error. When I remove the Datatables.mvc from references, the project compiles successfully and renders the view form controller as well.


public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);

setDbInitializer();
//Set current Controller factory as StructureMapControllerFactory
ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());
Microsoft.AspNet.SignalR.GlobalHost.DependencyResolver = SmObjectFactory.Container.GetInstance<Microsoft.AspNet.SignalR.IDependencyResolver>();
}
private static void setDbInitializer()
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<OnlineAcademyDbContext, Configuration>());
SmObjectFactory.Container.GetInstance<IUnitOfWork>().ForceDatabaseInitialize();
}
public class StructureMapControllerFactory : DefaultControllerFactory
{
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType == null)
{
throw new HttpException(404, $"Resource not found : {requestContext.HttpContext.Request.Path}");
}
return SmObjectFactory.Container.GetInstance(controllerType) as Controller;
}
}
protected void Application_EndRequest(object sender, EventArgs e)
{
HttpContextLifecycle.DisposeAndClearAll();
}
}



and this is the error when i called a view from areas and Datatable.mvc has been add to references:



System.Web.HttpException: Resource not found : url of area...
ControllerType is null



thanks all.




1 Answer
1



well. problem has been solved. the solution is change the computer. i think the iis or Os got confuse cause






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived