November Happy Hour will be moved to Thursday December 5th.

EPiServer.Cms.UI.AspNetIdentity causing error

Ian
Ian
Vote:
 

When installed, the EPiServer.Cms.UI.AspNetIdentity NuGet package is causing the following error: "There is no Membership Provider configured in web.config"

The only solution I've seen, found here (https://world.episerver.com/forum/developer-forum/CMS/Thread-Container/2018/1/sqlmembershipprovider-configuration-in-web-config/#187742), suggests that the only way to fix it is to remove the NuGet package from the solution, which is not an option. Can the EPiServer.Cms.UI.AspNetIdentity.ApplicationSecurityEntityInitialization initialization module that's causing the problem be programmatically removed, disabled from inside another initialization or some other approach? 

#258529
Edited, Jul 06, 2021 15:46
Vote:
 

Can you post the full stacktrace? that error should only happen when there is a code actively calls membership provider. 

#258563
Jul 07, 2021 8:22
Ian
Vote:
 

@Surjit - I have, but I unfortunately can't seem to get past this error.

@Quan - Sure, here's a full stack trace. To be clear, this is happening when I'm in the Admin > Search User/Group UI, so you're absolutely correct. I still need this UI to allow me to manage a few roles stored within the SqlMembershipProvider. It seems that once EPiServer.Cms.UI.AspNetIdentity is installed, the ability to see those users created by the existing SqlMembershipProvider is gone.

Error while searching for user.
System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Invalid column name 'Comment'.
Invalid column name 'IsApproved'.
Invalid column name 'IsLockedOut'.
Invalid column name 'CreationDate'.
Invalid column name 'LastLockoutDate'.
Invalid column name 'LastLoginDate'.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<Reader>b__c(DbCommand t, DbCommandInterceptionContext`1 c)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   --- End of inner exception stack trace ---
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__6()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   at EPiServer.UI.Admin.SearchUsers.BuildGridDataSource(IEnumerable`1 membershipColl)
   at EPiServer.UI.Admin.SearchUsers.BindData(Int32 newPageIndex)
#258578
Jul 07, 2021 19:41
Vote:
 

If you opt in for AspNetIdentity, your web.config/system.web should look like this

    <roleManager>
      <providers>
        <clear />
      </providers>
    </roleManager>
    <membership>
      <providers>
        <clear />
      </providers>
    </membership>
I suspect you still have your membership/rolemanager here which caused the exception.
EDIT: now I read your post carefully and yes, with the AspNetIdentity installed you can't manage users created by the membership provider. You can, however, migrate those. here is a start:
#258579
Edited, Jul 07, 2021 20:03
Ian
Vote:
 

My web.config is set up the way you suggest, with both the roleManager and membership configuration sections cleared.

I'm happy to manually re-create the users using the AspNetIdentity provider and ditch the SqlMembershipProvider altogether, but I ultimately still need to resolve the underlying error so that the "Search Users/Groups" admin function works as expected. 

#258580
Jul 07, 2021 20:16
Vote:
 

Hi Ian,

About that SQL error (entity framework), I think i've had similiar issue way back in some project with local environment and database only. What I recall it was related to switching to custom ASP.NET identity.

As you can see from the error, there are some columns which are not found and if you have initially used the Episerver ApplicationUser those columns would have been created by the initial entity framework initialization.

If you look at the DB table 'AspNetUsers' you should have those listed columns there but now missing those.

Look at the DB table '__MigrationHistory', most likely you have there only one row but that would show that wrong Identity has been initialized (without the missing columns):

  • IF correct type EPiServer.Cms.UI.AspNetIdentity.ApplicationUser has been used during initial setup the database should have one row in the migration history table
    • where 'ContextKey' column value should be the Episerver identity type: EPiServer.Cms.UI.AspNetIdentity.ApplicationDbContext`1[EPiServer.Cms.UI.AspNetIdentity.ApplicationUser]
  • IF some other identity has been used you have something totally different in the 'ContextKey' column, maybe for example your custom identity or the .NET Microsoft.AspNet.Identity.EntityFramework.IdentityUser or the generic type version of it
    • but anyways if this is your case, then you would need to revert for example to your previous good copy of the database or try to delete the __MigrationHistory tabel and restart your app to get it initialized

NOTE! I assume this is only happening in your local development environment and not in any other environments - so don't go just randomly deleting stuff in your other environments without first taking backups of DB ;-)

#258747
Jul 10, 2021 9:18
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.