我正在尝试将Google OpenID与Azure和Linux上托管的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软件包。
答案 0 :(得分:3)
所以看起来通过增加超时使其工作,如建议here。我按照建议将值设置得更高,但显然你可以测试最合适的值。
我也改变了我的代码。你会注意到上面的类包含一个回复方的静态变量。我将其更改为实例变量,因为我没有理由使用此模式。 DotNetOpenAuth的示例代码也不使用回复方类的静态实例。
除非有人能够建议为什么将它作为静态可能是个好主意,否则我会保留原样。