How to integrate IoC Membership provider with ASP.NET MVC

前端 未结 1 732
情深已故
情深已故 2020-12-02 14:02

I have a custom membership/roles provider that I use in my MVC controllers that I also want to have accessible to ASP.NET MVC, so I can use AuthorizationFilters, etc. Since

相关标签:
1条回答
  • 2020-12-02 14:17

    The simplest way to get this to work is to use ASP.NET's standard mechanism of <membership> in web.config. You just let it use the default constructor but you override Initialize() and pull the dependencies there. Use this as reference.

    Personally, due to things like this, I prefer to avoid the provider model altogether so I use an approach similar to the ones described in the MonoRail docs. IMHO it's less bloated and more flexible. In the end, it's just about setting HttpContext.User with a proper IPrincipal implementation which is what the AuthorizeAttribute uses.

    I recently blogged about a solution to do proper IoC with MembershipProviders.

    0 讨论(0)
提交回复
热议问题