Pergunta

I'm trying to make some downloads using cookie authentication doing:

var downloader = new BackgroundDownloader();
downloader.SetRequestHeader("Cookie", "JSESSIONID=" + App.LoginGateway.JSESSIONID);
downloader.SetRequestHeader("Cookie", "JSESSIONID=" + App.LoginGateway.JSESSIONID);

Until here everything works perfectly, the problem begins when I try to restore my downloads and my JSESSIONID is expired

IReadOnlyList<DownloadOperation> downloads = null;
downloads = await BackgroundDownloader.GetCurrentDownloadsAsync();

I tried to find where could I set the request Header again but I was not capable. If I create a new BackgroundDownloader where could I set it for my download Operation?? Some Help is very appreciated

Foi útil?

Solução

As of Windows 8.1, BackgroundTransfer does not support updating the headers associated with a DownloadOperation/UploadOperation after the operation has been created, even if the operation is Paused/Resumed. You'll need to abort the old download and create a new download with an updated JSESSIONID header.

When your application is launched, it should be using BackgroundDownloader.GetCurrentDownloadsAsync() to query for all the DownloadOperations that might have been occurring in the background while your app was suspended/terminated. Your application should then call AttachAsync on each DownloadOperation in order to attach progress and completion handlers. In this case, you should implement logic in your completion handler that can identify this particular error case and create a new download (with the new JSESSIONID) for the same content.

As an aside, if you go searching for other folks that need to post-process failed downloads like this, you may run across some people who are performing these checks in Background Tasks that they register to run on a periodic timer. While this may sound like a good idea (since it means you could retry your download without waiting for the next time the user brings your application to the foreground), keep in mind that BackgroundTransfer may hang if you attempt to call AttachAsync in a Background Task for an operation which was started in your foreground application code.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top