控制器'Viper.Web.Controllers.PartialController'的单个实例不能用于处理多个请求

时间:2019-02-08 09:36:44

标签: c# asp.net-mvc-5 autofac

我正在尝试使用AutoFac设置我的MVC5应用程序。我已经按如下所示注册了控制器。

builder.RegisterControllers(typeof(MvcApplication).Assembly).InstancePerRequest();

如果我运行该应用程序,并将以下内容包含在_Layout.cshtml

中,
<div id="container">
    @{ Html.RenderAction("Menu", "Partial"); }
</div>

然后我得到以下错误:

    Server Error in '/' Application.
A single instance of controller 'Viper.Web.Controllers.PartialController' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: A single instance of controller 'Viper.Web.Controllers.PartialController' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request.

Source Error: 


Line 9:  <body>
Line 10: <div id="container">
Line 11:     @{ Html.RenderAction("Menu", "Partial"); }
Line 12: </div>
Line 13: 

如果更改为使用InstancePerDependancy,则将遇到StackOverflow异常。

任何帮助/指导将不胜感激。

0 个答案:

没有答案