gpt4 book ai didi

c# - 使用 DotnetopenAuth 时报告和记录错误

转载 作者:行者123 更新时间:2023-11-30 14:15:25 26 4
gpt4 key购买 nike

想要连接 Withings API。我在另一个项目中使用了相同的 Controller ,他在那里工作得很好。在站点是 Azure webrole 的项目中(不知道这是怎么回事)它根本不起作用。首先我得到了

The type initializer for 'DotNetOpenAuth.Reporting' threw an exception.

所以我在web.config中关闭了它

reporting enabled="false"

现在我得到了

The type initializer for 'DotNetOpenAuth.Logger' threw an exception.

我不使用 log4net。

 public ActionResult StartOAuth()
{

var serviceProvider = GetServiceDescription();
var consumer = new WebConsumer(serviceProvider, _tokenManager);

// Url to redirect to
var authUrl = new Uri(Request.Url.Scheme + "://" + Request.Url.Authority + "/Withings/OAuthCallBack");

// request access
consumer.Channel.Send(consumer.PrepareRequestUserAuthorization(authUrl, null, null));

// This will not get hit!
return null;
}

private ServiceProviderDescription GetServiceDescription()
{
return new ServiceProviderDescription
{
AccessTokenEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/access_token", HttpDeliveryMethods.PostRequest),
RequestTokenEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/request_token", HttpDeliveryMethods.PostRequest),
UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/authorize", HttpDeliveryMethods.PostRequest),
TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() },
ProtocolVersion = ProtocolVersion.V10a
};
}

最佳答案

事实证明这是 Azure 的错。在 web.config 中有一个部分破坏了 DotnetOpenAuth。删除此部分是一种解决方法。可能添加 log4net 也会解决这个问题,但我没有测试。

<trace> 
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">

<filter type="" />
</add>
</listeners>
</trace>

关于c# - 使用 DotnetopenAuth 时报告和记录错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10189055/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com