OpenIdButton';s扩展返回null
下面是我用vb.net编写的代码 受保护的子OpenIdButton3_LoggedIn(ByVal sender作为对象,ByVal e作为DotNetOpenAuth.OpenId.relingparty.OpenIdEventArgs)处理OpenIdButton3.LoggedIn OpenIdButton3.Visible=False 作为索赔响应的Dim配置文件=e.Response.GetExtension(索赔响应的)() Dim email As String=profile.email MsgBox(电子邮件) 端接头 但是线路 Dim email As String=profile.email 正在给出以下错误 异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例 我已经阅读了相关文档,并在webconfig中实现了AXFetchAsSregTransform。下面是显示相同内容的块OpenIdButton';s扩展返回null,openid,dotnetopenauth,Openid,Dotnetopenauth,下面是我用vb.net编写的代码 受保护的子OpenIdButton3_LoggedIn(ByVal sender作为对象,ByVal e作为DotNetOpenAuth.OpenId.relingparty.OpenIdEventArgs)处理OpenIdButton3.LoggedIn OpenIdButton3.Visible=False 作为索赔响应的Dim配置文件=e.Response.GetExtension(索赔响应的)() Dim email As String=profile.
>
即使这样,我似乎得到了空值。我正在从谷歌获得认证
有人能帮我吗?最后,我找到了解决办法。将其张贴在此处,以便其他面临相同问题的人可以得到帮助 “全球声明——如果你出于某种原因在本地声明,它们似乎不起作用 Dim relyingParty作为新的开放式政党 Dim authResponse作为IAAuthenticationResponse 声明此项后,在web表单上创建一个按钮,允许用户登录Google。以及一个显示已登录用户的电子邮件id的标签 '将以下代码放在页面加载上 在按钮的单击事件中输入以下代码
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
你就完了
<add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth" />
</behaviors>
</relyingParty>
</openid>
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
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