2013-02-14 3 views
0

다음은 vb.net로 작성된 코드입니다.OpenIdButton의 확장은 null을 반환합니다.

서브 OpenIdButton3_LoggedIn 보호 (개체로 ByVal의 송신자 DotNetOpenAuth.OpenId.RelyingParty.OpenIdEventArgs로서 ByVal의 e)이 ClaimsResponse = E로 OpenIdButton3.LoggedIn

OpenIdButton3.Visible = 거짓

어둡게 프로필 핸들.문자열 = profile.Email

있는 MsgBox (이메일)으로

희미한 이메일() (ClaimsResponse의) Response.GetExtension

최종 하위

그러나 선

문자열 = profile.Email

으로

희미한 이메일은 다음과 같은 오류를주고있다.

예외 정보 : System.NullReferenceException : 개체 참조가 개체의 인스턴스로 설정되지 않았습니다.

관련 문서를 읽었으며 webconfig에서 AXFetchAsSregTransform을 구현했습니다. 다음은 같은 것을 보여주는 블록입니다.

<sectionGroup name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection, DotNetOpenAuth.Core"> 
    <section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true" /> 
    <section name="openid" type="DotNetOpenAuth.Configuration.OpenIdElement, DotNetOpenAuth.OpenId" requirePermission="false" allowLocation="true" /> 
    <section name="oauth" type="DotNetOpenAuth.Configuration.OAuthElement, DotNetOpenAuth.OAuth" requirePermission="false" allowLocation="true" /> 
    <section name="messaging" type="DotNetOpenAuth.Configuration.MessagingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" /> 
    <section name="reporting" type="DotNetOpenAuth.Configuration.ReportingElement, DotNetOpenAuth.Core" requirePermission="false" allowLocation="true" /> 
</sectionGroup> 

> < dotNetOpenAuth>

<openid> 

    <relyingParty> 

 <add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth" /> 

    </behaviors> 

    </relyingParty> 

</openid> 
</dotNetOpenAuth>

그렇다면 null 값을 얻는 것 같습니다. Google로부터 인증을 받고 있습니다.

아무도 도와 줄 수 있습니까?

답변

0

마지막으로 해결책을 찾았습니다. 같은 문제에 직면 한 다른 사람들을 도울 수 있도록 여기에 게시하십시오.

는 '글로벌 선언 - 당신은 로컬로 선언하면, 어떤 이유로, 그들이하지 작동하는 것 같다

희미한 relyingParty IAuthenticationResponse으로 새로운 OpenIdRelyingParty

희미한 authResponse로

다음을 신고하면 웹 양식에서 사용자가 Google에 로그온 할 수있는 버튼을 만듭니다. 그리고 로그인 한 사용자의 이메일 ID를 보여줄 lable입니다.

'페이지로드시 다음 코드를 입력하십시오. 버튼의 클릭 이벤트에

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
    Dim googleAppsDiscovery As New HostMetaDiscoveryService() With {.UseGoogleHostedHostMeta = True} 
    relyingParty.DiscoveryServices.Insert(0, googleAppsDiscovery) 

    authResponse = relyingParty.GetResponse() 

    If authResponse IsNot Nothing Then 
     If authResponse.Status = AuthenticationStatus.Authenticated Then 
      Dim fetch As FetchResponse = authResponse.GetExtension(Of FetchResponse)() 
      If fetch IsNot Nothing Then 
       ' Save user details in session variables 
       'Dim temp As [String]() = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email).ToString().Split("@"c) 
       Dim temp As String = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email).ToString() 
       If temp IsNot Nothing Then 
        Dim userName As String = temp 
        Label1.Text = "You are logged in as : " & userName 
       End If 
      End If 
     End If 
    End If 
End Sub 

넣고 다음 코드는

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 
    Dim currentPageURL As String = curPageURL.ToString 

    Dim urlRealm As New Uri(currentPageURL) 
    Dim urlReturn As New Uri(currentPageURL) 

    Dim rm As Realm = New Realm(urlRealm) 
    Dim gIdentifier As String = "https://www.google.com/accounts/o8/id" 

    Dim request As IAuthenticationRequest = relyingParty.CreateRequest(gIdentifier, urlRealm, urlReturn) 

    Dim fetch As New FetchRequest 

    fetch.Attributes.Add(New AttributeRequest(WellKnownAttributes.Contact.Email, True)) 
    request.AddExtension(fetch) 

    request.RedirectToProvider() 
End Sub 

추가는 현재 URL

Function curPageURL() As String 
    Dim s, protocol, port As String 

    If Request.ServerVariables("HTTPS") = "on" Then 
     s = "s" 
    Else 
     s = "" 
    End If 

    protocol = strLeft(LCase(Request.ServerVariables("SERVER_PROTOCOL")), "/") & s 

    If Request.ServerVariables("SERVER_PORT") = "80" Then 
     port = "" 
    Else 
     port = ":" & Request.ServerVariables("SERVER_PORT") 
    End If 

    curPageURL = protocol & "://" & Request.ServerVariables("SERVER_NAME") & _ 
      port & Request.ServerVariables("SCRIPT_NAME") 
End Function 

Function strLeft(ByVal str1 As String, ByVal str2 As String) As String 
    strLeft = Left(str1, InStr(str1, str2) - 1) 
End Function 

을 얻기 위해이 개 기능을 다음과 같은 작업이 완료된다.

관련 문제