How to enable Role Manager with SimpleMembership on ASP.NET MVC 4

前端 未结 2 2008
半阙折子戏
半阙折子戏 2021-02-02 00:33

I\'m wondering how to use the Role Manager feature with the SimpleMembership system included in ASP.NET MVC 4, specifically how to build a controller that manages a

相关标签:
2条回答
  • 2021-02-02 00:41

    Well, I am no expert on ASP.NET MVC4 but as a task I have set for myself, I wanted to create Role Based site access.

    ASP.NET MVC4 is an excellent resource! I do have complaints about the lack of information and difficulty to implement Roles in MVC4.

    To achieve the task one can implement SimpleMembership and SimpleRoles. See the below links:

    1. Using SimpleMembership With ASP.NET WebPages by Matthew M. Osborn
    2. SimpleMembership, Membership Providers, Universal Providers and the new ASP.NET 4.5 Web Forms and ASP.NET MVC 4 templates by Jon Galloway

    The above two links explain a lot and have some very basic code examples but unfortunately the solution download is not available in the first URL.

    In addition to the above:

    1. Customize the SimpleMembership in ASP.NET MVC 4.0 by thangchung
    2. ASP.NET MVC 4 Sample on MSDN

    This last article goes into a much better detail and also gives source code to peruse.

    0 讨论(0)
  • 2021-02-02 01:06

    In web.config add the following

    <profile defaultProvider="SimpleProfileProvider">
          <providers>
            <add name="SimpleProfileProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" connectionStringName="DNMXEntities" applicationName="/" />
          </providers>
        </profile>
        <membership defaultProvider="SimpleMembershipProvider">
          <providers>
            <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
          </providers>
        </membership>
        <roleManager defaultProvider="SimpleRoleProvider">
          <providers>
            <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
          </providers>
        </roleManager>
    
    0 讨论(0)
提交回复
热议问题