Google OpenID提供商始终在Azure上失败

Sim*_*sey 7 asp.net-mvc azure dotnetopenauth google-openid

我正在尝试将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
Run Code Online (Sandbox Code Playgroud)

我触发请求的代码是:

    //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();
    }
Run Code Online (Sandbox Code Playgroud)

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

<defaultProxy enabled="true">
  <proxy autoDetect="True" usesystemdefault="True" />
</defaultProxy>
Run Code Online (Sandbox Code Playgroud)

我正在使用nuget最新的4.2.2软件包.

Sim*_*sey 3

因此,看起来通过增加超时可以使其发挥作用,如此处建议的那样。我按照建议将值设置得较高,但显然您可以测试最合适的值。

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

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