我正在尝试将 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 包。