开发者

Pro ASP.net MVC Framework sample code not working

This is from a very good book by Steven Sanderson

I am trying to follow the chapter 4 and trying to setup IOC on my mvc code from the code sample of the book but its not working.

I follow the code from page 97 to page 101 where I set up Inversion of Control and run the code but I get the following error.

A dialog box opens trying to search the following file:

c:\TeamCity\b开发者_如何学PythonuildAgent\work\1ab5e0b25b145b19\src\Castle.Windsor\Windsor\WindsorContainer.cs

It seems like controllertype is null in the following line of code:

protected override IController GetControllerInstance(
    System.Web.Routing.RequestContext requestContext, 
    Type controllerType)
{
    return (IController)container.Resolve(controllerType);
}

The exception happens at the above return statement saying " {"Value cannot be null.\r\nParameter name: service"}"

This happens to be in WindsorContainerFactory.

Routes looks as follows:

public class MvcApplication : System.Web.HttpApplication
{
 public static void RegisterRoutes(RouteCollection routes)
 {
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Products", action = "List", id = ""} // Parameter defaults
    );
 }

 protected void Application_Start()
 {
    RegisterRoutes(RouteTable.Routes);
    ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory());
 }
}

Please help..

Thanks..


Your method is probably being called for requests that are not served by your app. For example for favicon.ico.

Make sure your controllerType is not null. If it is just return null and bypass the code that you added.

Different kind of browsers will make different "extra" requests to your site depending on how they cache. Also, if you are hosting the site with IIS vs Visual Studio Dev Server these might catch the request before it gets to your (e.g. IIS will server a .jpg file without having to letting go to your controller but the VS Dev Server might not)


You could try debugging the route.

http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx


So far I have found the following links addressing the same exact issue. I am copying them here for my own reference.

http://forums.asp.net/t/1559062.aspx?Pro+ASP.NET+MVC+-+setting+up+IOC+Castle+Windsor


First, I think it will be better if you let the relative link more than absolute link .

Second , check your browsers . I saw no error in your code . maybe different browsers will make it worse. Also, if you are hosting the site with IIS vs Visual Studio Dev Server these might catch the request . :D

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜