User data not persisting in DotNetBrowser component - c#

Using DotNetBrowser in WPF app in Windows 10. When navigating to certain pages that typically save user data and use it in subsequent loads to restore your settings, it doesn't seem to be happening.
See example code here of a very simple implementation. If I use it to browse to Amazon's site and login, after closing and reopening app, I'll need to login again -- in a normal browser like Chrome, it retains my login. Is something missing in the code to enable this similar behavior?

To make it work, I had to set UserDataDirectory when creating engine:
engine = EngineFactory.Create(new EngineOptions.Builder
{
RenderingMode = RenderingMode.HardwareAccelerated,
UserDataDirectory = $"{Environment.ExpandEnvironmentVariables("%AppData%\\MyApp\\Chromium\\User Data")}",
LicenseKey = ConfigurationManager.AppSettings["DotNetBrowserLicenseKey"],
}
.Build());

Related

Caching of "multiple sites" with Windows Phone 8.1

I have this weird problem my website won't cache the mainsite!
Here is a little overview about what I am trying to do
The first page that is being loaded is the
[DidTheUserLoggedInBefore?.html]
which checks if the user already has logged in or not depending on that result the user will be redirected to
either [LOGIN.html] or [MAINPAGE.HTML]
pretty simple!
But here comes the problem when the user restarts the app in Offline mode the App should redirect immediately to the mainpage (assuming the previous login was a success).
But that doesnt happen at all.
Instead the [DidTheUserLoggedInBefore?.html] from cache was called (which is correct) and starts loading the mainpage which isnt in cache which results in a whitescreen aka my error.
So how do I get my App to cache the Mainpage?
I've tried setting CacheSize to 100, but that didn't changed a thing :(
You can't check if the user has logged in with a .html file... You need some sort of server side language to set a cookie... Anyway this isn't much clear, is your "app" just a webview?
I couldn't let the webview cache more than 2 (simple) webpages...
WebView ignores he offline.manifest.php file too ...

Webkit embedded browser disable cookies

I'm using this borwser in .net 3.5 winform application, on x86 platform.
http://sourceforge.net/projects/webkitdotnet/
The problem, when I logged in facebook, with this browser, and I've got the data from facebook, and I closed the form, and after I reloaded the form (every control recreated) the facebook logged again. So the session continued. I don't want this, I'would like to begin a new session. Can I disable the cookies of browser, or reset session, or something like this?
public WebBrowserTabPage currentPage;
WebBrowserTabPage page = new WebBrowserTabPage();
tabControl.TabPages.Add(page);
currentPage = page;
currentPage.browser.Navigate(Url);
currentPage.browser is a WebKitBrowser instance.
I've seen about my problem, and I found a variable (CookiesPolicy in WebkitBrowser class. I've set up this to disable cookies, and facebook didn't worked without cookies. I've tried to delete the WebkitBrowser's cookies from hard drive, but I didn't find them. After I've dicovered, there is a memory leak with Webkitbrowser. So I closed the from, but it didn't disposed, and stayed in memory. Finally I solved the problem, I've put the WebkitBrowser in another Project, and I'm running in different Application.
I'm using Inter Process Communication (IPM) for communicating between mother form application and the browser application
After the browsers
Application.Exit();
the session is disposed, and I can sign into facebook again.
Here is the sample code for IPM with named Pipe:
http://www.codeproject.com/Articles/34073/Inter-Process-Communication-IPC-Introduction-and-S

How to start new IE session with Watin

I need to know how to start a browser instance but with a new session. I tried to clear cookies and clear cache but this doesn't give me what I need.
In my case I add products to a basket, then close the browser, then use another url that adds different product, but always the old products are still in the basket.
for IE6-7 you should start a new browser session in a new process like this:
var ie = new IE("yoururl", true);
for IE8-9 you should set the no-merge option on the settings class before creating a new IE instance:
Settings.MakeNewIe8InstanceNoMerge = true;
var ie = new IE("yoururl");
Make sure that you're closing the browser properly (i.e. closing all its tabs and windows, including downloads and such) - look at the task manager to see if it's still running. Session might not be cookie-based (for example, it could be tracked in the same process that processes the request), and clearing browser cache isn't going to affect the open sessions in any way.
Assuming that you're developing an asp.net application or website you may try to right-click on the ASP.NET Development Server icon in the system tray and stop it, then re-run your project. That should kill all sessions.
We had the same problem here. IE re-uses the session over all its browser instances. If you want a new session just do:
Alt (menu) -> File -> New Session
Check this blog for more info.
Sessions are managed by cookies, you can clear all your cookies or just for the site concerned.
Try searching for IE Clearing cookies
IE 9 has one more way of not clearing all the cookies.
If you open the Dialog to Clear Cookies from the Options Menu in IE 9, you will notice that the first options says "Preserve Favorites Website Data." Leave this unchecked and you usual clear cookies, close browser should work.
Let me know if this helps, I think this should do the trick ;)
I will be trying this in WatiN soon, but just testing with my commandline switches, it looks like I can open multiple instances using
iexplore.exe -private -nomerge
and each instance will not interfere with the other ones.
This means it allows you to login with differnet logins on the same website, and they won't interfere with each other.
This needs further verificaiton, but so far it seems to work.
update: I found this old patch for WatiN that adds the privacy feature to the watin lib, it doesn't appear to currently be in the release- http://sourceforge.net/tracker/?func=detail&aid=3013950&group_id=167632&atid=843730

How can I pass an argument from a web page that is loaded inside a web browser applet in a C# program, back to the C# application?

This is a probably a dumb question but here is what I've got.
A web developer has a secure login page that after a user logs into it, a database reference is made and it grants rights to a particular PDF file on our network. There is desire to have a custom locally designed application used to present that PDF file to the user, which is fine as I have used cpp code from Adobe to generate a stripped down viewer, however the problem I'm faced with is integrating his web application into my windows application.
It would be easier for me to just create my own login/database query, but then I'd basically be removing his entire piece of the project. That in itself presents a problem, as really this entire thing is his project and he asked me for help. So that's why I'm stuck with this situation where I"m attempting to insert a web applet in the application to present his login page. From that login page, after it authenticates, he can return a path to that particular file. He was previously just launching the associated PDF viewer (Acrobat), but what we need is a fully integrated solution. Make sense?
InvokeScript.
http://msdn.microsoft.com/en-us/library/cc491132.aspx
Have the webmaster write something like this:
<script type="text/javascript">
function getPdfPath() {
return "/path/to/my.pdf";
}
</script>
You should then be able to:
var path = (string) oWebBrowser.InvokeScript("getPdfPath");
Alternately, you could have him write you a web service.
Have a look at the ObjectForScripting property of the WebBrowser. It allows you to define an object whose methods can be called by Javascript code

How to launch a browser and later direct it to a page?

I need to launch a browser, do some work and then make the browser navigate to a URL (in that order).
The first part is of course simple and I have a Process object. I am at a loss as to how to later direct it to the target page?
How do I treat the Process as a browser and make it navigate to the desired page?
Any help, pointers, code snippets appreciated.
Instead of launching the browser & then navigating to the page, just tell the OS that you want to run the URL. Windows will pick the correct browser, and navigate the user to the given URL.
System.Diagnostics.Process.Start("http://www.StackOverflow.com");
If you don't need to do this in production, you could use a testing library such as WatiN to do this:
using WatiN.Core;
//Placeholder page to launch initial browser
IE ie = new IE("http://www.google.com");
DoSomeWork();
//Now navigate to the page you want
ie.GoTo("http://stackoverflow.com");
My first instinct for this question was DDE, but it appears that has been decommissioned in Windows Vista so that is no good. Shame, as it was the only consistent mechanism in Windows for Interprocess Communication (IPC)...oh how I miss Arexx on the Amiga.
Anyhow, I believe the following will work but unfortunately, due to the way it works, it launches Internet Explorer irrespective of the configured browser.
If your application has a Form, then create a WebBrowser control on it. Set this to non-visible as we are only making use of its as a launching device rather than to display the web page.
In code, at the point where you want to show a web page, use the following code:
webBrowser1.DocumentText = "window.open('How to launch a browser and later direct it to a page?', 'BananasAreOhSoYummy');";
What this does is to tell the WebBrowser control, which is just the IE in disguise, to open a new window called 'BananasAreOhSoYummy'. Because we have given the window a name, we can use that line repeatedly, with different URLs, to change the page in that particular browser window. (A new window will be opened if the user has happened to close it.)
I will have a think about an approach that honours the user's default browser choice.
If you don't need the actual instance of IE, you can use the System.Windows.Forms.WebBrowser control.
I think instead of sending the browser a url you could send it javascript that would run and direct the browser to a site.
Not sure if this would work but I see no reason why it wouldn't

Categories

Resources