Page 1 of 1

Tutorial for ADO.NET ASP.NET Identity 2 not working

Posted: Tue 26 May 2015 11:53
by nhill383
Hi,

I am trying to follow the tutorial for Using ADO.NET Implementation of ASP.NET Identity 2 for PostgreSQLhttps://www.devart.com/dotconnect/postg ... orial.html but i am having some problems getting it to work.

I got a number of compilation errors when following the steps in the tutorial. I was able to fix a couple of them but i am now stuck

section 5
i replaced with the following

Code: Select all

  Dim manager = New ApplicationUserManager(New PgSqlUserStore())
section 1
code from tutorial gave error, extension methiods can only be defined in modules. I converted the c# code and got the following

Code: Select all

Imports System.Security.Claims
Imports System.Threading.Tasks
Imports Microsoft.AspNet.Identity
Imports Devart.Common.Web.Identity
Imports Devart.Data.PostgreSql.Web.Identity
Imports ApplicationUser = Devart.Common.Web.Identity.IdentityUser

Namespace AspNet_Identity_Application.Models

    Public Module ApplicationUserExtensions
        <System.Runtime.CompilerServices.Extension> _
        Public Async Function GenerateUserIdentityAsync(ByVal user As ApplicationUser, ByVal manager As UserManager(Of ApplicationUser)) As Task(Of ClaimsIdentity)
            ' Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            Dim userIdentity = Await manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie)
            ' Add custom user claims here
            Return userIdentity
        End Function
    End Module
End Namespace
but i still get two compilation errors
'GenerateUserIdentityAsync' is not a member of 'Devart.Common.Web.Identity.IdentityUser'. IdentityConfig.vb 90

'GenerateUserIdentityAsync' is not a member of 'Devart.Common.Web.Identity.IdentityUser'. Startup.Auth.vb 29

I will attach the sample project which shows as far as i got.

please could the tutorial be updated to work properly.

I am using visual studio 2013 update 4 and obviously visual basic as opposed to c#

many thanks
Nick

Re: Tutorial for ADO.NET ASP.NET Identity 2 not working

Posted: Fri 29 May 2015 17:27
by Shalex
We will correct the tutorial https://www.devart.com/dotconnect/postg ... orial.html > the "Using Existing ASP.NET Identity Functionality" section in the following way:

2. Should be

Code: Select all

Imports System.Security.Claims
Imports System.Threading.Tasks
Imports Microsoft.AspNet.Identity
Imports Devart.Common.Web.Identity
Imports Devart.Data.PostgreSql.Web.Identity
Imports ApplicationUser = Devart.Common.Web.Identity.IdentityUser

Public Module ApplicationUserExtensions
    <System.Runtime.CompilerServices.Extension> _
    Public Async Function GenerateUserIdentityAsync(user As ApplicationUser, manager As UserManager(Of ApplicationUser)) As Task(Of ClaimsIdentity)
        ' Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        Dim userIdentity = Await manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie)
        ' Add custom user claims here
        Return userIdentity
    End Function
End Module
instead of

Code: Select all

Imports System.Security.Claims
Imports System.Threading.Tasks
Imports Microsoft.AspNet.Identity
Imports Devart.Common.Web.Identity
Imports Devart.Data.PostgreSql.Web.Identity
Imports ApplicationUser = Devart.Common.Web.Identity.IdentityUser

Namespace AspNet_Identity_Application.Models
    Public NotInheritable Class ApplicationUserExtensions
        Private Sub New()
        End Sub
        <System.Runtime.CompilerServices.Extension> _
        Public Shared Function GenerateUserIdentityAsync(user As ApplicationUser, manager As UserManager(Of ApplicationUser)) As Task(Of ClaimsIdentity)
            ' Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            Dim userIdentity = Await manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie)
            ' Add custom user claims here
            Return userIdentity
        End Function
    End Class
End Namespace
5. Should be

Code: Select all

Dim manager = New ApplicationUserManager(New PgSqlUserStore())
instead of

Code: Select all

Private manager As var = New ApplicationUserManager(New PgSqlUserStore())

Re: Tutorial for ADO.NET ASP.NET Identity 2 not working

Posted: Mon 01 Jun 2015 16:11
by nhill383
Thank you, that works now.

I noticed that it doesn't set the SecurityStamp field, not sure how important that it. The entity solution does set this field. I will most likely be using the entity solution now that it is working for winforms , http://forums.devart.com/viewtopic.php?f=30&t=31833

I will leave it up to you as to whether you think the tutorial should set the SecurityStamp field. It is working now and will allow users to be registered

thanks

Re: Tutorial for ADO.NET ASP.NET Identity 2 not working

Posted: Tue 02 Jun 2015 10:27
by Shalex
nhill383 wrote:I noticed that it doesn't set the SecurityStamp field, not sure how important that it. [...]
I will leave it up to you as to whether you think the tutorial should set the SecurityStamp field.
Thank you for your remark. We will investigate the question and notify you about the result.