简体   繁体   中英

Reporting and Logging errors while using DotnetopenAuth

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM