asp.net - 使用 MVC 4.0 的 DotNetOpenAuth

标签 asp.net asp.net-mvc dotnetopenauth asp.net-mvc-4

我一直在使用 ASP.Net MVC 4 Developer Preview 尝试 DotNetOpenAuth 示例。

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

  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 编译的,并且绑定(bind)重定向要么不起作用,要么扩展方法可能针对已弃用的方法起作用。

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

最佳答案

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

是的,DNOA 是针对 MVC 1.0 构建的,这是设计使然,因此它适用于所有版本的 MVC(给定适当的重定向)。这纯粹是 MVC 版本的事情——而不是 .NET 4.0 的事情。

关于asp.net - 使用 MVC 4.0 的 DotNetOpenAuth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8888072/

相关文章:

c# - 如何通过ID来操作itemtemplate中的item

asp.net-mvc - URL 中的点会导致 ASP.NET mvc 和 IIS 出现 404

asp.net-mvc - 如何使自定义错误页面出现在生产服务器上

asp.net - 如何重置 ASP.NET 启动页?

asp.net-mvc-4 - MVC4 中的 DotNetOpenAuth Twitter API 版本 1.1 调用

asp.net-mvc-2 - 发现多种类型与名为 'Home' 的 Controller 匹配

c# - 通过 DotNetOpenAuth 对 FreshBooks 进行身份验证

c# - 如何从 ASP.NET Identity 2.0 中的 PasswordReset token 获取 UserId?

javascript - 如何在没有回发的情况下发送电子邮件

ASP.NET Response.BinaryWrite 文件下载被 SSL 阻止