2011-12-21 36 views
1

我在我的asp.net 2.0和VS 2005中使用dotnetopenid。我只完成了這項工作,並且成功的身份驗證由me完成。我有一個登錄頁面,並且經過身份驗證它去food.aspx.I只想顯示food.aspx上的用戶的電子郵件地址在谷歌身份驗證後,我只做了以下工作的openid沒有別的,請告訴我我必須寫在login.aspx哪些代碼或food.aspx來顯示用戶的電子郵件地址。打開ID顯示電子郵件和用戶在網頁上的全名

<%@ Register Assembly="DotNetOpenAuth" Namespace="DotNetOpenAuth.OpenId.RelyingParty" TagPrefix="rp" %> 
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %> 

<rp:OpenIdLogin ID="OID" runat=server Identifier="https://www.google.com/accounts/o8/id" ></rp:OpenIdLogin> 

更新 我在login.aspx的

Protected Sub Page_Load(ByVal sender As Object, ByVal e As OpenIdEventArgs) 
     Dim openid As New OpenIdRelyingParty() 
     Dim request As IAuthenticationRequest = openid.CreateRequest("https://www.google.com/accounts/o8/id") 
     Dim fetch As New FetchRequest() 
     fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email) 
     request.AddExtension(fetch) 
     request.RedirectToProvider() 
    End Sub 

的頁面加載事件和頁面寫了這個代碼加載Evemt Food.aspx的編寫follwoing代碼

Dim openid As OpenIdRelyingParty = New OpenIdRelyingParty 
     Dim response = openid.GetResponse 
     If (Not (response) Is Nothing) Then 
      Select Case (response.Status) 
       Case AuthenticationStatus.Authenticated 
        Dim fetch = response.GetExtension 
        Dim email As String = String.Empty 
        If (Not (fetch) Is Nothing) Then 
         email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email) 
        End If 
        FormsAuthentication.RedirectFromLoginPage(response.ClaimedIdentifier, False) 
      End Select 
     End If 

但是在這一行的login.aspx頁面加載事件中仍然出現錯誤

fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email) 

錯誤是

AddRequired is not a member of System.Collections.ObjectModel.KeyedCollection 
(Of DotNetOpenAuth.OpenId.Extensions.AttributeExchange.AttributeRequest 

我可以爲這個

+0

請人給予回答我的問題 – 2011-12-21 05:05:48

+0

讓這個有#1隊的人誰可以解決我的問題 – 2011-12-21 06:17:49

回答

0

做當你的用戶將進行身份驗證自己ST谷歌什麼,他將重新回到您的網頁。 由於您使用的是開放式Id,因此您可以使用Attribute exchange在用戶被重定向回您的網頁時獲取用戶電子郵件和全名。

現在您只需從響應中提取用戶的電子郵件和姓名,並根據需要顯示/存儲它們。

下面是詳細介紹瞭如何利用上述庫

openid-trying-to-get-email-address-from-google-op

+0

爵士我不usingvb.net c#所以,我也將該代碼轉換爲vb.net,但在此代碼中存在編譯錯誤,並且還告訴我贏得了哪些事件代碼,我必須編寫或其他任何其他代碼,我必須在我的web應用程序中寫入 – 2011-12-21 06:28:35

+0

我只瞭解Java,但需要在2個步驟中編寫代碼1.當用戶被重定向到登錄頁面時2)用戶回到頁面尾部時呃認證。我相信你可以認爲我們的編譯問題,因爲他們必須是一些語言語法錯誤 – 2011-12-21 06:30:59

+0

http://stackoverflow.com/questions/8575088/display-open-id-email-on-web-page這是一個爲您提供 – 2011-12-21 06:32:12

相關問題