I realised that the website I linked to in my question is telling you how to migrate to Identity tables, but still use SimpleMembership. I want to use Identity throughout, so I created an empty MVC application using Visual Studio so that I could copy in the code I wanted and fix it up. Here are the steps I followed to get Login and Logout working:
- Added ApplicationUser.csto my Models project
- Added IdentityConfig.csto my App_Start folder
- Added Startup.Auth.csto my App_Start folder
- Added AccountController.csto my Controllers folder (renamed existing controller)
- Added Startup.csto root folder
- Added AccountViewModels.csto ViewModels folder
- Changed my context to inherit IdentityDbContext(it does indeed mean that new tables are created in a migration)
- Added the required NuGet packages and fixed up all the namespaces
- Project now builds
- But Add-Migrationgave an error ... "EntityType IdentityUserRole has no key defined"
- ....solved that by adding a call to base.OnModelCreatingin my override
- Add-Migration&- Update-Database- adds the tables required
- Added my custom fields in UserProfiletoApplicationUserand updated the database
- Used sql (in a migration) to copy data from old tables to new tables. Sql included here. NB need to populate SecurityStampwith a Guid to prevent error during Login
- That's got Login and Logout working
- Removed UserProfile,SimpleRoleProviderandRoleManagerclasses - replacing the code where necessary.
- Removed references to WebMatrix.DataandWebMatrix.WebDatadlls
- Removed <roleManager enabled="true" defaultProvider="simple">and<membership defaultProvider="simple">from web.config
Sql used in step 14:
INSERT INTO dbo.aspnetusers (id
, email
, emailconfirmed
, passwordhash
, securitystamp
, phonenumber
, phonenumberconfirmed
, twofactorenabled
, lockoutenddateutc
, lockoutenabled
, accessfailedcount
, username
, organisationid
, firstname
, lastname
, inactive)
    SELECT
        u.id,
        u.username Email,
        m.isconfirmed EmailConfirmed,
        m.password PasswordHash,
        --SignInManager.PasswordSignInAsync (used in Login method) 
        --throws an exception http://stackoverflow.com/a/23354148/150342
        NEWID() SecurityStamp, 
        u.telephone PhoneNumber,
        CASE
            WHEN u.telephone IS NULL THEN 0
            ELSE 1
        END PhoneNumberConfirmed,
        0 TwoFactorEnabled,
        NULL LockoutEndDateUtc,
        0 LockoutEnabled,
        m.passwordfailuressincelastsuccess AccessFailedCount,
        u.username,
        u.organisationid,
        u.firstname,
        u.lastname,
        u.inactive
    FROM dbo.userprofiles u
        INNER JOIN dbo.webpages_membership m
            ON m.userid = u.id
    WHERE NOT EXISTS (SELECT
        1
    FROM dbo.aspnetusers
    WHERE id = u.id)
INSERT INTO dbo.aspnetroles (id
, name)
    SELECT
        roleid,
        rolename
    FROM dbo.webpages_roles r
    WHERE NOT EXISTS (SELECT
        1
    FROM dbo.aspnetroles
    WHERE roleid = r.roleid)
 INSERT INTO dbo.aspnetuserroles (userid
    , roleid)
        SELECT
            userid,
            roleid
        FROM dbo.webpages_usersinroles ur
        WHERE NOT EXISTS (SELECT
            1
        FROM dbo.aspnetuserroles
        WHERE userid = ur.userid
        AND roleid = ur.roleid)