Welcome Guest Search | Active Topics | Sign In | Register

Downloading to shared folder with impersonation never finished Options
AiSatan
Posted: Thursday, December 14, 2017 8:02:22 AM
Rank: Advanced Member
Groups: Member

Joined: 2/11/2016
Posts: 35
Hi,
I have a problem,
I try to download file to a shared folder from service, I use impersonate, but seems browser ignore it and downloading never finished

there is the example project (example.zip), please install it as service for test, cmd command:

Code: C#
sc create TestService binpath="E:\Source\TestMacro\Oops\bin\Debug\Oops.exe S"


There are a couple of things:
1. Why is it not downloaded directly to the specified folder (I see that it try to download to the temp folder, but no file here)
2. Why is it hanging - is download on separate thread? Can we make it on same thread?

Please let me know if something also need from me
eo_support
Posted: Thursday, December 14, 2017 8:45:28 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Hi,

In order to run the browser engine in a different user context, you must use this method to start the browser engine explicitly:

https://www.essentialobjects.com/doc/eo.webengine.engine.start_overload_1.aspx

If you are not familiar with using browser engine explicitly, you can take a look of here:

https://www.essentialobjects.com/doc/webbrowser/advanced/engine.aspx

The basic steps are:

1. Create a new Engine object;
2. Start the Engine using the specific user;
3. Create a new ThreadRunner object and pass the engine to the ThreadRunner through its constructor;
4. Create and use WebView objects through that ThreadRunner object;

Internally the browser engine runs not just in different threads --- but in multiple child processes. So it is not possible for you to impersonate the calling thread to switch user for the browser engine.

I am not exactly sure which step hangs for you. However the easiest way for you to do a download is through this method:

https://www.essentialobjects.com/doc/eo.webbrowser.webview.download.aspx

Make sure you update to the latest build when you use this method because we have just fixed an issue with this method very recently.

If you still have problem please let us know.

Thanks!

AiSatan
Posted: Thursday, December 14, 2017 11:17:40 AM
Rank: Advanced Member
Groups: Member

Joined: 2/11/2016
Posts: 35
Thanks for answer, I will try.

By the way, can you please show me any replace for AllowJavaScriptOpenWindow after <18.0.9?
eo_support
Posted: Thursday, December 14, 2017 11:23:59 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Hi,

There is no direct replacement for this option. If you do not wish to open new window, you would just not handle WebView.NewWindow event and the new window won't be opened.

Thanks!
AiSatan
Posted: Thursday, December 14, 2017 11:56:51 AM
Rank: Advanced Member
Groups: Member

Joined: 2/11/2016
Posts: 35
But it's not the same behavior, isn't?
I mean, we want to prevent the javascript popups - not user initiated popups(like open link in google.com)
eo_support
Posted: Thursday, December 14, 2017 1:51:42 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Hi,

Yes. You are correct. They are not the same thing. Unfortunately this option is no longer available because the corresponding setting has been removed from the browser engine.

The easiest way for you to duplicate this feature is with the following code:

Code: JavaScript
webView.JSInitCode = "window.open = function(){};";


This disables window.open function by overwriting the default implementation with an empty function and should achieve the same result.

Thanks!
AiSatan
Posted: Friday, December 15, 2017 7:58:51 AM
Rank: Advanced Member
Groups: Member

Joined: 2/11/2016
Posts: 35
Thanks

So, I've tested the method with engine:

Code: C#
var engine = Engine.Create("engineName");
                    LogonUser("Test", "Neptun", "123", 9, 0, out var token);

                    var im = new WindowsIdentity(token);

                   // I also tried call im.Impersonate(); and write some file, it's work, but not for the browser

                    engine.Start(im);

                    var tr = new ThreadRunner("threadName", engine);
                    var wv = tr.CreateWebView();

                    wv.FileDialog += (sender, args) =>
                    {
                        args.Handled = true;
                        // path to the folder
                        args.Continue("\\\\Neptune\\wcu\\test3.rar");
                    };

                    wv.BeforeDownload += (sender, args) =>
                    {
                        Console.WriteLine("BeforeDownload " + Thread.CurrentThread.ManagedThreadId);
                    };

                    wv.DownloadUpdated += (sender, args) =>
                    {
                        Console.WriteLine("DownloadUpdated " + Thread.CurrentThread.ManagedThreadId);
                    };

                    wv.DownloadCompleted += (sender, args) =>
                    {
                        // never happens

                        Console.WriteLine("DownloadCompleted " + Thread.CurrentThread.ManagedThreadId);
                        _impersonation.Dispose();
                    };

                    tr.Post(() =>
                        wv.LoadUrlAndWait("https://www.win-rar.com/postdownload.html?&L=0"));


But it's still not work. DownloadCompleted event never fired and a file not exist.
it's also not work for "upload file",but we also want to download and upload using different users

I'm not sure how work your new Download method with events, seems I should call it manually, right? but it's not like that I need here

Quote:
I am not exactly sure which step hangs for you.


I see this events:
- BeforeDownload
- DownloadUpdated
- DownloadUpdated
- DownloadUpdated
- DownloadUpdated
- DownloadUpdated
- FileDialog
- DownloadUpdated
- DownloadUpdated
- DownloadUpdated
- DownloadUpdated
- BeforeDownload
- DownloadUpdated
- DownloadUpdated
- DownloadUpdated
- DownloadUpdated
- DownloadUpdated
- Nothing/Hang

as well, I've attached example in the first post

eo_support
Posted: Monday, December 18, 2017 5:58:37 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Hi,

Please make the following change to your code:

1. Do not handle FileDialog event;
2. Set args.ShowDialog = false in your BeforeDownload event handler, also remember args.FileName;

This should allow download the finish. After the download is done, you can move the file (the source file is args.FileName in step 2) to the final destination.

The most likely reason that the download hangs for you has to do with you try to save the result to a network drive. If this part fails, the download task will be suspended. In Google Chrome, this will result in an error message at the bottom of the browser window and user will be able to choose another file name and retry. However EO.WebBrowser does not have the corresponding UI to handle this situation. So the download task is suspended indefinitely.

To avoid this problem, you should allow the browser engine using the default file (in your temp folder), then once the download is done, you can move it to its final location using your own code. This way you will be able to catch/troubleshoot any error that may occur during this stage.

Please let us know if this resolves the issue for you.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.