我无法获取GetExtension方法中返回的电子邮件地址,但它包含在Google(我正在测试的OP)发回给我的网址中.
if (Page.IsPostBack) { using (var openid = new OpenIdRelyingParty()) { var request = openid.CreateRequest(Request.Form["openid_identifier"]); var fetch = new FetchRequest(); fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Contact.Email,true)); request.AddExtension(fetch); request.RedirectToProvider(); } } else { using (var openid = new OpenIdRelyingParty()) { var response = openid.GetResponse(); if (response != null) { switch (response.Status) { case AuthenticationStatus.Authenticated: var claimsResponse = response.GetExtension<FetchRequest>(); break; case AuthenticationStatus.Canceled: //this.loginCanceledLabel.Visible = true; break; case AuthenticationStatus.Setuprequired: //this.loginFailedLabel.Visible = true; break; // We don't need to handle Setuprequired because we're not setting // IAuthenticationRequest.Mode to immediate mode. ////case AuthenticationStatus.Setuprequired: //// break; } } } }
谁知道什么是错的?
解决方法
请尝试以下代码:
switch (response.Status) { case AuthenticationStatus.Authenticated: var fetch = response.GetExtension<FetchResponse>(); string email = String.Empty; if (fetch != null) { email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email); } break; //... }