同时采用DotnetopenAuth报告和记录错误 [英] Reporting and Logging errors while using DotnetopenAuth
问题描述
想和Withings API连接。我用同样的控制器在其他项目中,他完美地工作。在一个项目中,该网站是一个蓝色的webrole(不知道怎么说这个问题),它只是不工作。首先,我得到了
有关'DotNetOpenAuth.Reporting'的类型初始值引发了异常。
块引用>所以我关闭了它在web.config
启用报告=FALSE
块引用>现在我得到了
有关'DotNetOpenAuth.Logger'的类型初始值引发了异常。
块引用>我不使用log4net的。
公众的ActionResult StartOAuth()
{ 变种的ServiceProvider = GetServiceDescription();
VAR消费=新WebConsumer(的ServiceProvider,_tokenManager); // URL重定向到
VAR authUrl =新的URI(Request.Url.Scheme +://+ Request.Url.Authority +/ Withings / OAuthCallBack); // 申请进入
consumer.Channel.Send(消费prepareRequestUserAuthorization(authUrl,NULL,NULL)); //这不会得到打了!
返回null;
}私人ServiceProviderDescription GetServiceDescription()
{
返回新ServiceProviderDescription
{
AccessTokenEndpoint =新MessageReceivingEndpoint(https://oauth.withings.com/account/access_token,HttpDeliveryMethods.PostRequest)
RequestTokenEndpoint =新MessageReceivingEndpoint(https://oauth.withings.com/account/request_token,HttpDeliveryMethods.PostRequest)
UserAuthorizationEndpoint =新MessageReceivingEndpoint(https://oauth.withings.com/account/authorize,HttpDeliveryMethods.PostRequest)
TamperProtectionElements =新ITamperProtectionChannelBindingElement [] {新HmacSha1SigningBindingElement()},
ProtocolVersion = ProtocolVersion.V10a
};
}
解决方案因此,原来这是天青的错。在
的web.config
有它打破了部分的 DotnetOpenAuth 。删除这部分是一个解决方法。可能添加的 log4net的也将解决这个问题,但我没有测试。<跟踪和GT;
<&听众GT;
<加上TYPE =Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener,Microsoft.WindowsAzure.Diagnostics,版本= 1.0.0.0,文化=中性公钥= 31bf3856ad364e35NAME =AzureDiagnostics><滤波器类型=/>
< /添加>
< /听众>
< /跟踪>Wanted to connect with the Withings API. I used the same Controller in an other project, where he worked perfectly. In a project where the site is an Azure webrole(don't know how that is the issue) it just doesn't work. First I got
The type initializer for 'DotNetOpenAuth.Reporting' threw an exception.
So I turned it off in the web.config
reporting enabled="false"
Now I got
The type initializer for 'DotNetOpenAuth.Logger' threw an exception.
I don't use 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 }; }
解决方案So it turns out it was Azure's fault. In
web.config
there is a section which broke DotnetOpenAuth. Deleting this section is a workaround. Probably adding log4net would also fix this issue, but I didn't test.<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>
这篇关于同时采用DotnetopenAuth报告和记录错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!