c# – 使用DotNetOpenAuth从OpenID Provider获取电子邮件地址

c# – 使用DotNetOpenAuth从OpenID Provider获取电子邮件地址,第1张

概述我无法获取GetExtension方法中返回的电子邮件地址,但它包含在Google(我正在测试的OP)发回给我的网址中. if (Page.IsPostBack){ using (var openid = new OpenIdRelyingParty()) { var request = openid.CreateRequest(Request.Form["ope 我无法获取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;    //...}
总结

以上是内存溢出为你收集整理的c# – 使用DotNetOpenAuth从OpenID Provider获取电子邮件地址全部内容,希望文章能够帮你解决c# – 使用DotNetOpenAuth从OpenID Provider获取电子邮件地址所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1248539.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存