asp.net和Identity Server 3

时间:2019-01-30 01:08:29

标签: asp.net identityserver3

我正在尝试使用Identity Server版本3验证我的应用程序。但是,当我这样做时,出现错误。这是我的代码:

Startup.Auth.vb:

Partial Public Class Startup
     Public Sub ConfigureAuth(app As IAppBuilder)
              app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType)
              app.UseCookieAuthentication(New CookieAuthenticationOptions())

             app.UseOpenIdConnectAuthentication(New OpenIdConnectAuthenticationOptions() With {
               .ClientId = clientId,
               .Authority = authority,
               .RedirectUri = "https://localhost:44321/",
               .Scope = OpenIdConnectScope.OpenIdProfile,
               .ResponseType = OpenIdConnectResponseType.IdToken,
               .TokenValidationParameters = New TokenValidationParameters() With {
               .ValidateIssuer = False
            },
            .Notifications = New OpenIdConnectAuthenticationNotifications() With {
                .AuthenticationFailed = AddressOf OnAuthenticationFailed
        }
        })

     End Sub
     Private Function OnAuthenticationFailed(ByVal context As AuthenticationFailedNotification(Of OpenIdConnectMessage, OpenIdConnectAuthenticationOptions)) As Task
        context.HandleResponse()
        context.Response.Redirect("/?errormessage=" & context.Exception.Message)
        Return Task.FromResult(0)
    End Function

end class

登录页面:

Protected Sub manuanSignIn(ByVal sender As Object, ByVal e As EventArgs) Handles manualLogin.Click
    If (Not Request.IsAuthenticated) Then
        Dim newAuth As AuthenticationProperties = New AuthenticationProperties()
        newAuth.RedirectUri = "/"           
        HttpContext.Current.GetOwinContext().Authentication.Challenge(newAuth, OpenIdConnectAuthenticationDefaults.AuthenticationType)

    End If
End Sub

尝试登录时遇到的错误是:

  

远程主机强行关闭了现有连接

任何人都对导致此问题的原因以及如何解决它有想法?

1 个答案:

答案 0 :(得分:0)

添加此内容可解决此问题:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12