在默認的AccountController創建我看到如何在asp.net web api 2中自定義身份驗證到我自己的表中?
public AccountController()
: this(Startup.UserManagerFactory(), Startup.OAuthOptions.AccessTokenFormat)
{
}
在Startup.Auth.cs我看到
UserManagerFactory =() =>
new UserManager<IdentityUser>(new UserStore<IdentityUser>());
好像UserStore執行來自Microsoft.AspNet.Identity.EntityFramework 。
因此,定製驗證我必須實現我自己UserStore的版本一樣
class MYSTUFFUserStore<IdentityUser> : UserStore<IdentityUser>
{
}
和覆蓋的方法,然後爲此在Startup.Auth.cs
UserManagerFactory =() =>
new UserManager<IdentityUser>(new MYSTUFFUserStore<IdentityUser>());
我我正在尋找一種正確的方式來定製認證。
謝謝你的答案,但我怎麼可以從另一個控制器獲得'AppUser'當前請求? –
'User.Identity.Name'會爲您提供經過驗證的請求中的用戶名。 – sunil
偉大的文章和解釋。謝謝,sunil。 –