Visual Basic WebControl - Add a Header

Posted on 2006-11-19
Last Modified: 2012-05-05
I am using the IE WebControl in a Visual basic container as a custom browser.  I need to pass some unique information via the browser to my web server and believe the best way to do this would be to read some local information (like a serial number in the registry entry for my browser app) into a HTTP header.    I have seem some posts about doing this on a link by link basis but I want this information to persist throughout an application session.

I am entirley new to software such as Visual Studio Express/Basic Express which has got me this far.....I simply want to a custom browser (which btw can only navigate my app) reporting something unique about the local installation to my web server so I can track installations.

Question by:davie455
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 17981221
What you want to do is pass this information via your User Agent String (UAS).

Put the information in the following registry entry on the local workstation with the browser control.  You'll need to do this on every workstation.  

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\User Agent\Post Platform]
"My Unique User Agent String" = "Anything"

When the browser connects to the server, it will send this string along with its normal user agent string as part of the GET requests.  You can then parse the request to see if it's the browser you're interested in.

Author Comment

ID: 17982183
Thanks Dan7el,

I have used User Agent String as a method before in gecko browers such as k-meleon but not IE.

I have tested this by manually adding an entry to the registry and for sure the string name I enter appears in the headers although I cannot see the string value.  This solution would work for me but I want the WebControl/Visual Basic App to report a different User Agent String than standard IE.

To recap, the purpose of all of this is...

1.   I want my web app accessible only via this customer browser and not IE.   If the UA string does not match a database entry then IP and other details are logged and the user is politley told to go away.  Therefore i need the IE useragent to not include this custom string.

2.   Where the UA string does match a database entry i will know exactly which physical installation/device is accessing for each session as i will issue a unique UA string per installation.  (imagine on install of my VB app containing the webcontrol the user enters a serial which gets written to the registry entry you suggest as the UA and is valid for only one install.)

Hope this makes sense,

Thanks for your help

Author Comment

ID: 17983143
This page...

....seems to describe a solution which works when a link is clicked only.....I am 100% a newbie in the area of C++, Visual Basic or indeed any language other than ASP, HTML and JScript.   I have Visial Basic 2005 Express Edition, a single form containing a webcontrol and nothing else (defaul webcontrol URL is my app).  I need somebody to walk me through applying the right code literally click by click, I have tried but it's so new to me that my progress is poor.


Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 17983729
You don't want to do all that.

Looks like one of the overloads for the Navigate method will allow you to add a string that identifies the control.

Author Comment

ID: 17984143
yes perfect, a string which identifies the control where the string is variable and set at installation and only applies to the control and not IE.   So, an overload for the Navigate method, step by step how do I do that please?

LVL 20

Accepted Solution

Daniel Van Der Werken earned 400 total points
ID: 17984366
Imports System
Imports System.Windows.Forms.WebBrowser

Public Class Form1
    Private myByte(1) As Byte

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        myByte(1) = 0

        WebBrowser1.Navigate("", String.Empty, myByte, "Additional Header Information")

    End Sub
End Class

Author Comment

ID: 17989541
Thanks Dan7el,

I have put this code into Form1.vb in Visual Basic 2005 Express Edition, when I debug the code the window launches but there is a DNS error of somekind (right click the window and I get..."res://ieframe.dll/dnserrordiagoff_webOC.htm#" as the URL) .   Clearly I am missing something, apologies I really do have no experience whatsoever here...can you image what i am doing wrong?

From the moment I launch VB 2005 Express Edition and start a new project what should I do step by step?  In recognition of the extra detail I need i have increased the Point value.

Many Thanks again.


Author Comment

ID: 17991377
actually have this working now, when the vb app lauches the first page load the Header I set persists.....but on redirect and I assume A HREF links the customer header is can I ensure this persists.

Also, a 500 point question if somebody can give me an example of how to read a registry entry into the customem header.


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sameEnds challenge 25 117
countX 22 159
Change to event 1 126
Problem to Alipay 10 67
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article will show, step by step, how to integrate R code into a R Sweave document
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question