|
Rank: Newbie Groups: Member
Joined: 4/22/2024 Posts: 7
|
Hello
i set on code this:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'Initialize the WebView using the PictureBox's window handle
m_WebView.Create(PictureBox1.Handle) 'Load Google's home page into the WebView m_WebView.Engine.Options.CustomUserAgent = "123456" m_WebView.Url = "http://localhost:50122/clienti.aspx"
End Sub
Where localhost is my own web page, in my web page i set this user agent check on page load: Label1.Text = Request.Headers("User-Agent").ToString()
But instead of get "123456" in label 1 i get usual useragent : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
Why i want modificate user agent?
Because i want my website will open only with custom browser EO webbrowser based
Thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,206
|
Hi,
You need to set your user agent BEFORE you create any WebView object.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 4/22/2024 Posts: 7
|
Thanks a lot
I have done , and it works.
My intent is that my asp website will be navigable only from my custon browser EssentialObject based.
Can you suggest me some way?
I can manage executable code and asp.net code.
I tryed setting a customuseragent property like "4764477" and made a check on asp.net webpages load that display only if detect "4764477" user agent, this way worked but i have a trouble, making this particular "custom" user agent name the page is very bad displayed and almost not usable ( listbox with blank , desized, decentrated etc)
At end i am searching a way to make website navigable only from essential object based custom browser
Thanks A lot for help you are giving as
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,206
|
Hi, You don't have to replace the entire user agent. You can just add something to it. For example, you can set it to:
Code:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 4764477
This way your website will still think the browser is Chrome and render the correct HTML, but you can still check whether your custom value "4764477" is present in the user agent string. Another way to do it is add a custom header entry in BeforeRequestLoad event: https://www.essentialobjects.com/doc/eo.webbrowser.webview.beforerequestload.htmlYou can then check if the custom header entry is present in your server side code. Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 1/15/2015 Posts: 48
|
Is there a good way to get the current UserAgent so we can set EO.WebEngine.EngineOptions.Default.CustomUserAgent?
I want to do something like: EO.WebEngine.EngineOptions.Default.CustomUserAgent = CurrentUserAgent + " MyCustomAgent/1.2.3.4";
At the moment we have to hard code the current user agent, and make sure to change it every time we update EO and Chromium version changes.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,206
|
Unfortunately no, there is no way to do that without actually creating a WebView. So the only way to do that is to:
1. Create a WebView, then use webView.EvalScript("window.navigator.userAgent) to get the user agent; 2. Stop the Engine. This is necessary for any changes of CustomUserAgent to take effect; 3. Set the new CustomUserAgent; 4. Continue to create WebView in your application;
Obviously, this might be a little over kill.
|
|