I am trying to use Google OpenID with an MVC 4 application hosted on Azure and it continues to fail. Not right away. When I deploy the application, it all works out fine over time. Then I leave it for a while, usually for one day, but it may be an hour, and then try again, and this fails every time. Then you update and return to the home page, which sends you to the login page, and it works again.
mistake:
[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
My code that triggers the request is:
//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(); }
I did not add anything superfluous to web.config, except for proxy configuration settings recommended in other places. It doesn't seem to make any difference.
<defaultProxy enabled="true"> <proxy autoDetect="True" usesystemdefault="True" /> </defaultProxy>
I am using the latest 4.2.2 packages from nuget.
Simon halsey
source share