簡體   English   中英

多線程身份驗證失敗C#

[英]Authentication failing with multiple threads c#

我當前正在編寫一個提供一些數據庫操作的Web應用程序。 該系統還需要能夠處理不同的數據庫。問題在於,必須使用RESTful api中的數據更新數據庫中的某些字段。 為了執行這些更新,我使用Quartz.NET時間表來為每個需要更新的表創建一個作業,該作業檢查是否需要更新相關的數據庫。 如果是這樣,它將從REST服務獲取信息。 當我不使用多線程時,訪問REST服務不會有任何問題。 但是,當我使用Quartz.net時,服務器會為某些請求返回401錯誤。 此行為是不穩定的,並非總是會發生。 我正在使用RestSharper使用用於摘要身份驗證的自定義身份驗證器進行這些調用。 我在這里得到此解決方案:
http://www.ifjeffcandoit.com/2013/05/16/digest-authentication-with-restsharp/

我還在該帖子中使用了auth fixer。

創建工作:

            foreach (KeyValuePair<string, int> tabel in DataParser.getAllTabellenMetRefresh())
        {
            // define the job and tie it to our class
            IJobDetail job = JobBuilder.Create<LocatieUpdater>()
                .WithIdentity("dbUpdaterJob"+count, "group1")
                .UsingJobData("type", tabel.Key)
                .Build();

            // Trigger the job to run now, and then every x seconds
            ITrigger trigger = TriggerBuilder.Create()
              .WithIdentity("myTrigger"+count, "group1")
              .StartNow()
              .WithSimpleSchedule(x => x
                  .WithIntervalInMinutes(tabel.Value)
                  .RepeatForever())
              .Build();
            sched.ScheduleJob(job, trigger);

這段代碼中的響應接收401。

var client = new RestClient(gegevens["Url"]);

        client.Authenticator = new DigestAuthenticator(ConfigAcces.getCredentials()[0], ConfigAcces.getCredentials()[1]);


        var request = new RestRequest(gegevens["request"], Method.GET);
        request.AddParameter("fields", "all");
        request.AddParameter(velden["TagId"], id);
        IRestResponse response = client.Execute(request);

我和提琴手一起看了看這個請求,但沒有發現任何有用的東西。 任何幫助或提示將非常歡迎。 提前致謝!

不能完全確定如何解決此問題,但是所有身份驗證似乎都可以通過禁用SyncronisationContext的使用並使該方法等待任務來進行。

  var request = new RestRequest(gegevens["request"], Method.GET);
    request.AddParameter("fields", "all");
    request.AddParameter(velden["TagId"], id);
        client.UseSynchronizationContext = false;
        IRestResponse response = await client.ExecuteTaskAsync(request);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM