最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Object reference not set to an instance of an object when do Unbind in Logout ItFoxtec - Stack Overflow

programmeradmin1浏览0评论

Object reference not set to an instance of an object when do Unbind in Logout ItFoxtec. Stack: at ITfoxtec.Identity.Saml2.Saml2RedirectBinding.UnbindInternal(HttpRequest request, Saml2Request saml2RequestResponse, String messageName) at ITfoxtec.Identity.Saml2.Saml2Binding.Unbind(HttpRequest request, Saml2Response saml2Response) at AuthSAML.ReciveLogoutResponse() in C:\inetpub\wwwroot\sistemapensiones\App_Code\AuthSAML.vb:line 149

I have a problem, I have a integration with Entra ID in VB .NET 4.8, It sn´t MVC, It´s a hibryd. I can´t validate the logout correctly, only it´s say Null Reference, also, sometimes my code doesn´t run very well, For example,in my code, when Entra redirect to my Logout, I execute the function ReciveLogoutResponse(), and my function do this:

Partial Class Logout
    Inherits System.Web.UI.Page

    Dim aSAML As New AuthSAML()
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

        If (Request.IsAuthenticated) Then
            'cierro sesión de SSO
            aSAML.SendLogoutRequest()
        Else
            'cierro sesión de SSO
            aSAML.ReciveLogoutResponse()
            Response.Redirect("~/Login.aspx")
        End If
    End Sub

Here, when code it´s in 'binding.Unbind(samlRequest, saml2LogoutResponse), the program throw an exception, "NULL REFERENCE". I don´t know how execute this instruction for validate my logout.

Also, when I wanted debug with LogError that it´s a function that write in txt file, the program looks like that the function sometimes execute, and other no. Like a async function, but isn´t.

For example, sometimes throw the error and the other execution no, so I don´t know what´s happen, because I put the code directly in the View Logout, and doesn´t work.

 Public Sub ReciveLogoutResponse()
     Try

         Dim saml2LogoutResponse As New Saml2LogoutResponse(saml2Config)
         Dim binding As New Saml2RedirectBinding()


         Dim samlRequest As New ITfoxtec.Identity.Saml2.Http.HttpRequest()

         samlRequest.Method = HttpContext.Current.Request.HttpMethod

         samlRequest.QueryString = HttpContext.Current.Request.QueryString.ToString()

         samlRequest.Form = New NameValueCollection()
         For Each key As String In HttpContext.Current.Request.Form.Keys
             samlRequest.Form.Add(key, HttpContext.Current.Request.Form(key))
         Next
         Using reader As New StreamReader(HttpContext.Current.Request.InputStream)
             samlRequest.Body = reader.ReadToEnd()
         End Using

         Dim samlXml As String = HttpContext.Current.Request.HttpMethod

         'binding.Unbind(samlRequest, saml2LogoutResponse)

         FederatedAuthentication.SessionAuthenticationModule.DeleteSessionTokenCookie()
         FederatedAuthentication.SessionAuthenticationModule.SignOut()
     Catch ex As Exception
         modulo_local.log_error_Guardar(ex.Message & "Stack:" & ex.StackTrace, ex.Message & "Stack:" & ex.StackTrace, ex.Message & "Stack:" & ex.StackTrace, 1)
     End Try

I see the code in the page:

LoggedOut method in the Auth Controller
After successfully or failing logout the logged out method receive the response.
[Route("LoggedOut")]
public IActionResult LoggedOut()
{
    var httpRequest = Request.ToGenericHttpRequest(validate: true);
    httpRequest.Binding.Unbind(httpRequest, new Saml2LogoutResponse(config));

    return Redirect(Url.Content("~/"));
}

And doesn´t work for my, the Entra ID give me the response because it´s look like a query response.

Object reference not set to an instance of an object when do Unbind in Logout ItFoxtec. Stack: at ITfoxtec.Identity.Saml2.Saml2RedirectBinding.UnbindInternal(HttpRequest request, Saml2Request saml2RequestResponse, String messageName) at ITfoxtec.Identity.Saml2.Saml2Binding.Unbind(HttpRequest request, Saml2Response saml2Response) at AuthSAML.ReciveLogoutResponse() in C:\inetpub\wwwroot\sistemapensiones\App_Code\AuthSAML.vb:line 149

I have a problem, I have a integration with Entra ID in VB .NET 4.8, It sn´t MVC, It´s a hibryd. I can´t validate the logout correctly, only it´s say Null Reference, also, sometimes my code doesn´t run very well, For example,in my code, when Entra redirect to my Logout, I execute the function ReciveLogoutResponse(), and my function do this:

Partial Class Logout
    Inherits System.Web.UI.Page

    Dim aSAML As New AuthSAML()
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

        If (Request.IsAuthenticated) Then
            'cierro sesión de SSO
            aSAML.SendLogoutRequest()
        Else
            'cierro sesión de SSO
            aSAML.ReciveLogoutResponse()
            Response.Redirect("~/Login.aspx")
        End If
    End Sub

Here, when code it´s in 'binding.Unbind(samlRequest, saml2LogoutResponse), the program throw an exception, "NULL REFERENCE". I don´t know how execute this instruction for validate my logout.

Also, when I wanted debug with LogError that it´s a function that write in txt file, the program looks like that the function sometimes execute, and other no. Like a async function, but isn´t.

For example, sometimes throw the error and the other execution no, so I don´t know what´s happen, because I put the code directly in the View Logout, and doesn´t work.

 Public Sub ReciveLogoutResponse()
     Try

         Dim saml2LogoutResponse As New Saml2LogoutResponse(saml2Config)
         Dim binding As New Saml2RedirectBinding()


         Dim samlRequest As New ITfoxtec.Identity.Saml2.Http.HttpRequest()

         samlRequest.Method = HttpContext.Current.Request.HttpMethod

         samlRequest.QueryString = HttpContext.Current.Request.QueryString.ToString()

         samlRequest.Form = New NameValueCollection()
         For Each key As String In HttpContext.Current.Request.Form.Keys
             samlRequest.Form.Add(key, HttpContext.Current.Request.Form(key))
         Next
         Using reader As New StreamReader(HttpContext.Current.Request.InputStream)
             samlRequest.Body = reader.ReadToEnd()
         End Using

         Dim samlXml As String = HttpContext.Current.Request.HttpMethod

         'binding.Unbind(samlRequest, saml2LogoutResponse)

         FederatedAuthentication.SessionAuthenticationModule.DeleteSessionTokenCookie()
         FederatedAuthentication.SessionAuthenticationModule.SignOut()
     Catch ex As Exception
         modulo_local.log_error_Guardar(ex.Message & "Stack:" & ex.StackTrace, ex.Message & "Stack:" & ex.StackTrace, ex.Message & "Stack:" & ex.StackTrace, 1)
     End Try

I see the code in the page:

LoggedOut method in the Auth Controller
After successfully or failing logout the logged out method receive the response.
[Route("LoggedOut")]
public IActionResult LoggedOut()
{
    var httpRequest = Request.ToGenericHttpRequest(validate: true);
    httpRequest.Binding.Unbind(httpRequest, new Saml2LogoutResponse(config));

    return Redirect(Url.Content("~/"));
}

And doesn´t work for my, the Entra ID give me the response because it´s look like a query response.

Share Improve this question asked Feb 5 at 22:38 Carlos Alfredo Tejeda AraujoCarlos Alfredo Tejeda Araujo 212 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

Microsoft Entra ID do not support SAML 2.0 Single Logout, implemented in method ReciveLogoutResponse (you do not need this method). After successfully logout Entra ID should be redirected back to the LoggedOut method.

Looks like the issue might be with how the SAML response is being handled before calling Unbind(). Vegas sweeps app, make sure the request isn't empty before processing it. You should try logging the request details before Unbind() to see what's missing. Also, check if saml2LogoutResponse is properly initialized before using it.

发布评论

评论列表(0)

  1. 暂无评论