【问题标题】:Reporting and Logging errors while using DotnetopenAuth使用 DotnetopenAuth 时报告和记录错误
【发布时间】:2012-04-17 09:59:04
【问题描述】:

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

“DotNetOpenAuth.Reporting”的类型初始化程序引发异常。

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

报告启用=“假”

现在我得到了

“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
        };
    }

【问题讨论】:

    标签: c# asp.net-mvc-4 dotnetopenauth


    【解决方案1】:

    所以事实证明这是 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>
    

    【讨论】:

    • 哇。感谢分享。如果您也可以尝试重新处理错误,并捕获异常详细信息,以便我们知道到底出了什么问题(您可能需要查看 InnerException),我很想听听您的发现。
    • 内部异常是{"Could not create Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35."}
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    • 2022-08-14
    • 2017-09-13
    • 1970-01-01
    • 2011-04-03
    相关资源
    最近更新 更多