asp.net-mvc – 为什么我的ClaimsRequest返回null?
我刚刚开始尝试DotNetOpenAuth项目.修改示例OpenIdRelyingPartyMvc项目,我能够获得ClaimRequest for Email以与Google合作.
但是,当我尝试将OpenID添加到我自己的项目时,ClaimResponse总是返回null.我想知道是否存在我缺少的项目或环境设置? 这是我的Authenticate方法: public ActionResult Authenticate(string returnUrl) { var response = openid.GetResponse(); if (response == null) { // Stage 2: user submitting Identifier Identifier id; if (Identifier.TryParse(Request.Form["openid_identifier"],out id)) { try { IAuthenticationRequest req = openid.CreateRequest(Request.Form["openid_identifier"]); req.AddExtension(new ClaimsRequest { Email = DemandLevel.Require }); return req.RedirectingResponse.AsActionResult(); } catch (ProtocolException ex) { ViewData["Message"] = ex.Message; return View("Login"); } } else { ViewData["Message"] = "Invalid identifier"; return View("Login"); } } else { // Stage 3: OpenID Provider sending assertion response switch (response.Status) { case AuthenticationStatus.Authenticated: ClaimsResponse sreg = response.GetExtension<ClaimsResponse>(); if (sreg != null) { var email = sreg.Email; Session["Email"] = email; } Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay; FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier,false); if (!string.IsNullOrEmpty(returnUrl)) { return Redirect(returnUrl); } else { return RedirectToAction("Index","Home"); } case AuthenticationStatus.Canceled: ViewData["Message"] = "Canceled at provider"; return View("Login"); case AuthenticationStatus.Failed: ViewData["Message"] = response.Exception.Message; return View("Login"); } } return new EmptyResult(); } } 解决方法<configuration> <configSections> <section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true"/> </configSections> <dotNetOpenAuth> <openid> <relyingParty> <behaviors> <!-- The following OPTIONAL behavior allows RPs to use SREG only,but be compatible with OPs that use Attribute Exchange (in various formats). --> <add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform,DotNetOpenAuth" /> </behaviors> </relyingParty> </openid> </dotNetOpenAuth> </configuration> http://dotnetopenauth.net:8000/wiki/CodeSnippets/OpenIDRP/AXFetchAsSregTransform 将配置信息添加到web.config.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc-3 – Amazon CloudFront Cache失效策略,以确保
- asp.net – .net 4.6框架是在位升级,那么.net framework 4.
- asp.net – 使用linq进行Datalist分页
- asp.net – 如何检查列表<>包含TimeSpan上的比较
- asp.net – 无法使用URL重写出站规则来更改IIS响应代码
- asp.net-mvc – asp.net MVC antiorgerytoken异常RedirectT
- 剃刀 – 我应该在哪里包含视图组件的脚本?
- asp.net – 如何隐藏用户控件并删除它的空间
- asp.net-mvc-4 – ModelBinder和子模型
- asp.net mvc 中使用async/await异步编程
- asp.net – Gridview行编辑 – 动态绑定到DropDo
- asp.net – 在WAP转换期间无法解析.aspx
- asp.net-mvc – 为什么System.ComponentModel.Da
- 如何在ASP.NET应用程序中有效地缩放和裁剪图像?
- asp.net-mvc-3 – 在生产环境中使用DropCreateDa
- asp.net-mvc – ASP.NET MVC:HTTPContext和依赖
- asp.net – <%=%>和<%#%>之间有什么区别?
- 将自定义属性添加到asp.NET RadioButton控件
- asp.net-mvc-3 – ASP.NET MVC如何从Controller访
- asp.net-mvc – 在ASP.net MVC单元测试中访问Mod