7

我正在尝试将 Google OpenID 与托管在 Azure 上的 MVC 4 应用程序一起使用,但它一直失败。不过不是马上。当我部署应用程序时,它一次又一次地完美运行。然后我将它放置一段时间,通常是一天,但可能是一个小时,然后再试一次,每次都失败。然后您刷新,返回主页,它会将您发送到登录页面并再次运行。

错误是:

[InvalidOperationException: Sequence contains no elements]
   System.Linq.Enumerable.First(IEnumerable`1 source) +498
   DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) +106

[ProtocolException: No OpenID endpoint found.]
   DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.CreateRequest(Identifier userSuppliedIdentifier, Realm realm, Uri returnToUrl) +303
   Tools.Helpers.GoogleApps.Login(Uri returnUrl) in c:\Users\Simon\Documents\Visual Studio 2012\Projects\Internal Utils\Website\Helpers\GoogleApps.cs:33
   Tools.Helpers.ExternalLoginResult.ExecuteResult(ControllerContext context) in c:\Users\Simon\Documents\Visual Studio 2012\Projects\Internal Utils\Website\Helpers\ExternalLoginResult.cs:25
   System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +33
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +613
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +263
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +230
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +20
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +20
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +20
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375

我触发请求的代码是:

    //constructor
    static GoogleApps()
    {
        var googleAppDiscovery = new HostMetaDiscoveryService
        {
            UseGoogleHostedHostMeta = true,
        };

        RelyingParty = new OpenIdRelyingParty();
        RelyingParty.DiscoveryServices.Insert(0, googleAppDiscovery);
    }

    public void Login(Uri returnUrl)
    {
        var realm = new Realm(returnUrl.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped));

        var request = RelyingParty.CreateRequest("my.domain.name", realm, returnUrl);

        var fetch = new FetchRequest();
        fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Contact.Email, true));
        fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Name.First, true));
        fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Name.Last, true));
        request.AddExtension(fetch);

        request.RedirectToProvider();
    }

除了在其他地方推荐的代理配置设置之外,我没有在 web.config 中添加任何额外内容。似乎没有任何区别。

<defaultProxy enabled="true">
  <proxy autoDetect="True" usesystemdefault="True" />
</defaultProxy>

我正在使用来自 nuget 的最新 4.2.2 包。

4

1 回答 1

3

所以看起来通过增加超时使其工作,如建议的here。我按照建议将我的值设置得更高,但显然您可以测试最合适的值。

我也改变了我的代码。您会注意到上面的类包含回复方的静态变量。我将其更改为实例变量,因为我认为没有理由使用此模式。DotNetOpenAuth 的示例代码也不使用Replying Party 类的静态实例。

除非有人能提出为什么将它作为一个静态可能是一个好主意,否则我会保持原样。

于 2013-06-17T15:54:22.730 回答