English 中文(简体)
DotNetOpenAuth;AsActionResult不工作
原标题:DotNetOpenAuth; AsActionResult does not work

范围方法

AsActionResult()

does not work. I get string "DotNetOpenAuth.Messaging.OutgoingWebResponseActionResult" to response instead of redirect to provider. namespace

using DotNetOpenAuth.Messaging;

其中包括。 问题在哪里?

[ADDED] my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.RelyingParty;
using System.Web.Security;
    public class UserController : Controller
    {
        private static OpenIdRelyingParty openIdProvider = new OpenIdRelyingParty();

        public ActionResult Authenticate(string userOpenId)
        {
            // Ответ с сайта провайдера.
            IAuthenticationResponse response = openIdProvider.GetResponse();

            // response равен null, если запроса на OpenID провайдер мы не делали.
            if (response == null)
            {
                Identifier id;
                // Пытаемся распарсить OpenID клиента.
                if (Identifier.TryParse(userOpenId, out id))
                {
                    try
                    {
                        // Делаем редирект на сайт провайдера OpenID
                        return
                            openIdProvider
                            .CreateRequest(userOpenId)
                            .RedirectingResponse
                            .AsActionResult(); // Расширение для MVC
                    }
                    catch (ProtocolException ex)
                    {
                        ViewData["Message"] = ex.Message;
                    }
                }
                else
                {
                    // Не корректный OpenID клиента
                    ViewData["Message"] = "Invalid identifier";
                }
                return View("Login");
            }
            else
            {
                // Ответ с сайта провайдера OpenID
                switch (response.Status)
                {
                    // Успешная аутентификация
                    case AuthenticationStatus.Authenticated:
                        {
                            Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay;
                            // Аутентифицированы по cookies.
                            FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false);
                            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");
                        }
                    // При прочих, делаем редирект на главную.
                    default:
                        {
                            return RedirectToAction("Index", "Home");
                        }
                }
            }
        }


    }
最佳回答

I found solution - need to check web.config and be sure, that all libraries compiled to .NET 3.0. Correct keys:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly xmlns="">
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

不正确:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly xmlns="">
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
问题回答

暂无回答




相关问题
On what .NET Framework(s) is DotNetOpenAuth available?

Most (all?) OAuth resources - both information about the protocol and code libraries for easily using them in your own applications - one seems to find on the internet seem to assume the application ...

Twitter update access with OAuth and DotNetOpenAuth

I m trying to use OAuth with .NET (DotNetOpenAuth) to send updates to a Twitter account via a web application. I understand the basic workflow of OAuth and Twitter. Where I m confused if is it useful ...

ActionResult redirect renders using ToString()

Using the following sample: http://www.west-wind.com/Weblog/posts/899303.aspx The following line... return req.RedirectingResponse.AsActionResult(); renders the string "DotNetOpenAuth.Messaging....

OpenID provider on localhost with DotNetOpenAuth

I have the DotNetOpenAuth sample provider running locally and it appears to correctly handle requests via the web browser. I can step through the handler for authorisation in the debugger. I have a ...

热门标签