ASP.NET Identity

出自ProgWiki
跳至導覽 跳至搜尋

ASP.NET Identity

技術文件

FAQ

登入

'必需
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin
Imports System.Web
Imports System.Web.UI
Imports Microsoft.Owin.Security
 
'登入
Dim manager = New UserManager()
Dim user As ApplicationUser = manager.Find(UserName.Text, Password.Text)
If user IsNot Nothing Then
    IdentityHelper.SignIn(manager, user, RememberMe.Checked)
    IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
Else
    FailureText.Text = "Invalid username or password."
    ErrorMessage.Visible = True
End If

登出

'必需
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin
Imports System.Web
Imports System.Web.UI
Imports Microsoft.Owin.Security
 
'登出
If (User.Identity.IsAuthenticated) Then
    Me.Context.GetOwinContext().Authentication.SignOut()
End If