1

我正在從https://github.com/IdentityServer/IdentityServer3.Samples/tree/master/source/AspNetIdentity運行IdentityServer AspNetIdentity示例。本身,將app.config中的數據庫設置爲(LocalDb),它可以工作。Thinktecture IdentityServer 3 - ASP.NET身份示例不起作用

我也在MVC 5 + Web API 2項目上完成了File/New Project。我在Azure SQL中創建了一個SQL數據庫,將新項目指向該數據庫,並在那裏創建了一個新用戶,這意味着ASP.NET Identity已經運行了數據庫創建腳本,並且在那裏有通常的表格。

所以,單獨地,他們很好。

然後我進入了AspNetIdentity示例,並將它指向剛創建的新創建的SQL數據庫。當我運行樣本時......它爆炸了。具體來說,在AspNetIdentityUserService.cs的188行中,它調用UserManager。

protected async virtual Task<TUser> FindUserAsync(string username) 
    { 
     return await userManager.FindByNameAsync(username); 
    } 

例外:

SelfHost.vshost.exe Error: 0 : [Thinktecture.IdentityServer.Core.Configuration.Hosting.ErrorPageFilterAttribute]: 8/20/2015 7:26:40 PM +00:00 -- Exception accessing: /core/login 
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 'FirstName'. Invalid column name 'LastName'. 
    at System.Data.SqlClient.SqlCommand.<>c__DisplayClass16.<ExecuteDbDataReaderAsync>b__17(Task`1 result) 
    at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() 
    at System.Threading.Tasks.Task.Execute() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.<ExecuteStoreCommandsAsync>d__c.MoveNext() 
--- End of inner exception stack trace --- 
    at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.<ExecuteStoreCommandsAsync>d__c.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
etc. 

我誤解的東西嗎? AspNetIdentity插件不能從常規格式的ASP.NET身份數據庫中提取?

回答

1

該示例使用基本ASP.NET標識的擴展版本IdentityUser。請參閱User entity

這增加了屬性FirstNameLastName,根據你的例外,你的數據庫沒有。

+0

Scott - 感謝您的答覆和您的博客文章,如https://www.scottbrady91.com/Identity-Server/Identity-Server-3-using-ASPNET-Identity。確實很有幫助。 – Scott

+0

不用擔心,很高興幫助! –

相關問題