Using SimpleMembership with EF model-first

后端 未结 5 1845
孤城傲影
孤城傲影 2020-12-02 19:15

Can SimpleMembership be used with EF model-first? When I try it, I get \"Unable to find the requested .NET Framework Data Provider\" when

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 19:49

    That's a bug in MVC 4. There's a workaround in this blog post.

    As an action filter, InitializeSimpleMembershipAttribute hooks into OnActionExecuting to perform the lazy initialization work, but this can be too late in the life cycle. The Authorize attribute will need the providers to be ready earlier if it needs to perform role based access checks (during OnAuthorization). In other words, if the first request to a site hits a controller action like the following:

    [Authorize(Roles="Sales")]
    

    .. then you’ll have an exception as the filter checks the user’s role but the providers aren’t initialized.

    My recommendation is to remove ISMA from the project, and initialize WebSecurity during the application start event.

提交回复
热议问题