Ninject MVC3 ASP.NET CustomMembershipService 与 Sqlite 设置
我在配置自定义 asp.net 会员服务时遇到问题。
绑定模块时,我在应用程序启动时收到一条烦人的消息,如下所示:
this.Bind<RoleProvider>()
.ToConstant(Roles.Providers["SQLiteRoleProvider"]);
this.Bind<MembershipProvider>()
.ToConstant(Membership.Providers["SQLiteMembershipProvider"]);
This method cannot be called during the application's pre-start initialization stage.
At
>System.Web.dll!System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
in {System.Web.Compilation.BuildManager} System.Web.Compilation.BuildManager
我检查了很多博客和诸如
.net 控制台应用程序生命周期 - 解决 pre -从 BuildManager.GetReferencedAssemblies 开始初始化错误
也但是没有任何成功。
以前有人遇到过这个错误消息吗?
I ran into a problem configuring a custom asp.net membership service.
I've got an annoying message on application startup when binding modules, here it is :
this.Bind<RoleProvider>()
.ToConstant(Roles.Providers["SQLiteRoleProvider"]);
this.Bind<MembershipProvider>()
.ToConstant(Membership.Providers["SQLiteMembershipProvider"]);
This method cannot be called during the application's pre-start initialization stage.
At
>System.Web.dll!System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
in {System.Web.Compilation.BuildManager} System.Web.Compilation.BuildManager
I've check a bunch of blogs and SO question like
ASP.NET: This method cannot be called during the application's pre-start initialization stage
also but haven't any success.
Has anyone encountered this error message before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改绑定代码将解决该问题。
只需让
SQLiteMembershipProvider
和SQLiteRoleProvider
实现IProvider
即可。如果你推迟初始化它就会恢复正常。
Changing the binding code will fix the problem.
Just make the
SQLiteMembershipProvider
andSQLiteRoleProvider
implementing theIProvider
.If you postpone the initialization it's gonna get right.
我也遇到了很大的问题。提供者的一些问题与 Ninject 不能很好地配合。我一直没弄清楚。我决定将其修复而不是注入。我将所有内容抽象为服务,并针对该服务类进行 Ninject 绑定。我最终得到了一个对我的实体框架成员资格提供程序进行硬编码使用的服务,如果我需要另一个提供程序,我将必须实现另一个对该提供程序进行硬编码的服务。
使用简单服务类进行注入是可行的,但不能通过
ToConstant()
直接绑定到提供程序。全局.asax.cs
I had huge problems with that too. Something about providers that doesn't work well with Ninject. I never figured it out. I decided to make it fixed rather than injected. I abstracted everything into a Service and made the Ninject bindings against this service class. I ended up with a Service that has hardcode use of my Entity Framework membership provider and if I need another provider I will have to implement another service that has that provider hardcoded.
Injection with a simple service class works but it does not with the
ToConstant()
direct binding to the provider.global.asax.cs