加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 带有MVC 4.0的DotNetOpenAuth

发布时间:2020-12-16 04:06:55 所属栏目:asp.Net 来源:网络整理
导读:我一直在尝试使用ASP.Net MVC 4 Developer Preview的DotNetOpenAuth示例. 我可以从我的测试页面成功调用我的Action,但由于一行代码而遇到了一个奇怪的问题: var request = _openid.CreateRequest(openIdUrl); var fetch = new FetchRequest(); fetch.Attrib
我一直在尝试使用ASP.Net MVC 4 Developer Preview的DotNetOpenAuth示例.

我可以从我的测试页面成功调用我的Action,但由于一行代码而遇到了一个奇怪的问题:

var request = _openid.CreateRequest(openIdUrl);
  var fetch = new FetchRequest();
  fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
  fetch.Attributes.AddRequired(WellKnownAttributes.Name.First);
  fetch.Attributes.AddRequired(WellKnownAttributes.Name.Last);
  request.AddExtension(fetch);
  //return RedirectToAction("Login");
  return request.RedirectingResponse.AsActionResult(); // <-- This is the line throwing the error

如果我注释掉有问题的代码行并在此之前取消注释,我再也看不到运行时错误了.

到目前为止,我尝试过:

1)确保我有正确的重定向:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        </dependentAssembly>
    </assemblyBinding>
    <legacyHMACWarning enabled="0" />
</runtime>

2)拥有正确的命名空间:

using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
using DotNetOpenAuth.OpenId.Extensions;

在我看来,DotNetOpenAuth DLL是针对MVC V 1.0.0编译的,绑定重定向要么不起作用,要么扩展方法可能对弃用的方法有效.

MVC版本:4.0.0.0
DotNetOpenAuth版本:3.4.7.11121

任何有关使用MVC 4的帮助都将非常感激.
MVC错误屏幕图像如下:

Image of Error Screen

更新
我发现AsActionResult是问题的原因,可能是因为扩展方法与.Net 4.0不兼容.我可以从request.RedirectingResponse获取OutgoingWebResponse对象但是知道如何将它转换为ActionResult

解决方法

您的绑定重定向似乎已损坏.请注意System.Web.Mvc如何出现两次?尝试删除第二个,因为第一个看起来正确.

是的,DNOA是针对MVC 1.0构建的,这是设计使得它适用于所有版本的MVC(给定适当的重定向).这纯粹是一个MVC版本的东西 – 而不是.NET 4.0的东西.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读