0

What's the best way to upgrade my previous CustomRoleProvider to the new providers in Asp.Net MVC 5. I just implemented those methods and rolled out my own tables (because it's a multiple database web application).

What would be the easiest and fastest way to upgrade my authentication?

My previous web.config

  <roleManager enabled="true" defaultProvider="MyCustomRoleProvider" cacheRolesInCookie="true" createPersistentCookie="true">
  <providers>
    <clear />
    <add name="MyCustomRoleProvider" type="FacturatieMVCv2.Web.Core.MyCustomRoleProvider" />
  </providers>
</roleManager>

And my RoleProvider

Imports FacturatieMVCv2.Service
Imports FacturatieMVCv2.Domain.Common
Imports System.Web
Imports FacturatieMVCv2.Web.Core

Public Class MyCustomRoleProvider
    Inherits System.Web.Security.RoleProvider


    Dim _userService As Master.UserService
    Public Sub New(ByVal UserService As Master.IUserService)
        _userService = UserService
    End Sub
    Public Sub New()

    End Sub
    Public Overrides Sub AddUsersToRoles(usernames() As String, roleNames() As String)
    End Sub

    Public Overrides Property ApplicationName As String
        Get
            Return My.Application.Info.AssemblyName
        End Get
        Set(value As String)

        End Set
    End Property

    Public Overrides Sub CreateRole(roleName As String)
        Throw New NotImplementedException("UsesBitWiseOperations, change the ENUM Field")
    End Sub

    Public Overrides Function DeleteRole(roleName As String, throwOnPopulatedRole As Boolean) As Boolean
        Throw New NotImplementedException("UsesBitWiseOperations, change the ENUM Field")
    End Function

    Public Overrides Function FindUsersInRole(roleName As String, usernameToMatch As String) As String()
        Return _userService.FindUsersInRole(roleName, usernameToMatch).Select(Function(el) el.UserName)
    End Function

    Public Overrides Function GetAllRoles() As String()
        Return _userService.GetAllRoles
    End Function

    Public Overrides Function GetRolesForUser(username As String) As String()
        Return _userService.GetRolesForUser(username)
    End Function

    Public Overrides Function GetUsersInRole(roleName As String) As String()
        Return _userService.GetUsersInRole(roleName).Select(Function(el) el.UserName)
    End Function

    Public Overrides Function IsUserInRole(username As String, roleName As String) As Boolean
        Return _userService.IsUserInRole(username, roleName)
    End Function

    Public Overrides Sub RemoveUsersFromRoles(usernames() As String, roleNames() As String)
        _userService.RemoveUsersFromRoles(usernames, roleNames)
    End Sub

    Public Overrides Function RoleExists(roleName As String) As Boolean
        Return _userService.RoleExists(roleName)
    End Function
End Class
NicoJuicy
  • 3,435
  • 4
  • 40
  • 66
  • IMO you need to formulate more specific questions. This question comes across somewhat as 'please fix my code'. It might not be meant that way, but the question is vague. – MeanGreen Sep 05 '14 at 14:37
  • It's actually more of a Asp.Net MVC 4 vs Asp.Net MVC 5 Identity / Authentication issue. Everything was fine before (using customProviders), but now with the new Asp.Net identity i have some problems migrating to the latest methods... Eg. My roles are admin/support and users in an Enum. Now they are using Claims. I can't be more specific because it's about the Asp.Net authentication of the past vs now. – NicoJuicy Sep 08 '14 at 09:48
  • I really don't understand your point. The Membership Providers did not change in MVC5. There is the new ASP.NET Identity, but if you're not using it, that won't matter. The old providers still work just as they always did. Your problem is likely related to something else. Did you also upgrade to a newer version of IIS? What's more, giving us code that just calls other customer code we can't see doesn't help very much... We don't know what your User service does... Nor are you showing us where the actual problem is occurring (the initialization in the Pre app start) – Erik Funkenbusch Sep 08 '14 at 14:26

1 Answers1

0

You need to get rid of all mentions of roleManager and membershipProvider in your web.config. New Identity framework is not direct update from MembershipProvider. And it usually a lot of work for upgrading. Have you seen this guide for upgrading?

trailmax
  • 34,305
  • 22
  • 140
  • 234