Webbrowser control issue with cookies - c#

i have created web browser control in c#. I used to open .net website into this control. Once page is completely loaded.i was using cookies of this browser control to create httprequest and used to execute request. I used to get data which was needed for me.
But all of sudden this stopped working. I checkd to see what happened then i found that issues are with cookies are being formed throught browser control.For example, if i use page url on IE browser and then get cookie and supply it to httprequest. It works good. But same thing with web browser control is not working now.
Another thing, Forget about httprequest, Download from webbrowser control itselft is also failing. But its working in IE. What could be stopping it to download fail in web browser control and work in IE.
Dont understand how.please help.

This issue is not with the cookies. it is with the browser emulation. By default webbrowser control take IE emulation. but if you need to mention which browser version you want control to use. By using registry.

I emulated IE to my application by changing registry information. and it started working.

Related

Why doesn't the browser redirect to sign-inpage, when we add parameters to the Url?

I'm working on an add-in for Outlook from Ms Office. Basically we have integrated a part of our web application in Outlook by using a Webview2 in C#.Net (this used to be a WebBrowser control). The problem I'm having, is that the page should redirect to the sign-in page if the user is not signed in. But it doesn't, at least not when we use the complete link. The page does not redirect, and we get a 302 response.
Let's say we try to connect to example.com/index.php?page=settings&action=edit, we would be redirected to example.com/login.php That's actually working fine.
But we're adding parameters to let the browser know we're working with Outlook. so example.com/index.php?page=settings&action=edit&compact=true&outlookVersionCode=2&outlookVersion=1.0.1
This doesn't work. It has worked before, back when we used the WebBrowser control, which uses Internet Explorer. Now we replaced it with a WebView, which's rendering engine is Edge (Chromium).
Even when we just add "compact=true", it doesn't redirect. I've tested this in Chrome, Firefox and Edge, and it all gave the same result.
Edit: In Internet Explorer it somehow works just fine.
Kind regards,
Dries

Open Website containing Javascript code

I want to open some websites which may contain javascript code for example google analytics or piwik. I think the using a webclient is the easiest way to visit websites but does the webclient run javascript code in the background automaticly or how could I get javascriptcode running by visiting a website in C#?
Have you considered using a headless browser like PhantomJS.
If you are looking for something with a UI interface, look at the WebBrowser Control.
If you need to just get the DOM or underlying elements of the DOM, I would suggest Watin. It is very mature and works well and its fast.
WebClient only loads data from the web. It does not interpret it in any way.
If you need to treat the page the way a web browser would, then you need to use a Web Browser control.
in C# there is an Internet Explorer control. You can execute javascript code on a client PC by setting web URL link to this control. Internet Explorer control is a fully functional browser which executes all client code.

Invoke javascript methods on a page

Is there a way using either C# or a scripting language, such as Python, to load up a website in the user's default webbrowser and continue to interact it via code (e.g. invoke existing Javascript methods)? When using WinForms, you can host a Webbrowser control and invoke scripts from there, but only IE is supported. Is there a way of doing the same thing in the user's default browser (not necessarily using WinForms)?
Update: The website is stored on the user's machine, not served from a third party server. It is a help page which works dynamically with my C# program. When the user interacts with my C# program, I want to be able to execute the Javascript methods on the website.
You might want to look into Selenium. It can automate interaction with FireFox, IE, Chrome (with chromedriver) and Opera. It may not be suitable for your purposes due to the fact that it uses a fresh, stripped down profile, rather than the user's normal browser profile.
If you look at the HTTP request header you can determine the user-agent making the request. Based upon that information you can write logic from the server side as to respond with a unique page per detected user-agent string. Then you add any unique JavaScript you want as a static string to be executed by the user-agent application.

How do I change the user agent string of a WebBrowser control?

I am need to have 7 tabs all having web browser controls and each should have different user agent.I saw this and thought how do they do that?
http://www.howtogeek.com/howto/18450/change-the-user-agent-string-in-internet-explorer-8/
and using this for as implementation
Changing the user agent of the WebBrowser control
works like this if i change one browsers string all get same
User-Agent is an HTTP header field. There are many ways to change it. For Firefox there are definitely plugins you can download that let you modify your HTTP headers on the fly. There is probably a plugin that will let you do do this on a per-tab basis.
This sounds like a browser-specific question. But, in general, when it comes to HTTP, you can send whatever you want. Your browser does it automatically for you, but for Firefox, at least, you can download plugins that give you more control. For other browsers there might be a config file or setting that you can edit.
If you're writing a web browser that lets you do this feature, well, that should be easy as well; the API you are using should let you modify the headers.

Directly Navigating a Browser with an XBAP

I'm working on a full-trust WPF browser application (XBAP) and have come across a snag. An application on the client is wired to handle navigation requests with a certain prefix/protocol. (For example, 'foo://...") Additionally, the application handles these differently depending on which browser creates the request. I've tried the Page's 'NavigationService.Navigate()' method, but for some strange reason this involves WebRequest objects, which raises a NotSupportedException saying "The URI prefix is not recognized." I can create a WebBrowser control and successfully navigate IT with this prefix, but the application recognizes it as a different browser and reacts differently. If I were using Silverlight, I'd be to directly set the browser's 'window.location' which works perfectly. But of course, this is only appears to be available in the Silverlight framework.
So bottom line, what I need to do is trigger the browser hosting the XBAP to navigate to a URI with this special prefix.
Whew. That's all, I think. Thanks.
Update: The .Net Framework 4.0 will allow direct access to the browser's DOM which will solve this problem, however I am still scrounging for ways of accomplishing this in .Net 3.x.
You can try to use BrowserInteropHelper.ClientSite to access the DOM. Check out this post for a sample:
http://blogs.msdn.com/changov/archive/2009/03/01/scripting-out-of-an-xbap.aspx
Note that this would only work for Internet Explorer though.

Categories

Resources