使用DotnetopenAuth时报告和记录错误

Łuk*_*nik 3 c# dotnetopenauth asp.net-mvc-4

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

'DotNetOpenAuth.Reporting'的类型初始化程序引发了异常.

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

报告已启用="false"

现在我知道了

'DotNetOpenAuth.Logger'的类型初始化程序引发了异常.

我不使用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
        };
    }
Run Code Online (Sandbox Code Playgroud)

Łuk*_*nik 7

事实证明这是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>
Run Code Online (Sandbox Code Playgroud)