Add custom http request headers using BeforeNavigate2

Add-in Express™ Support Service
That's what is more important than anything else

Add custom http request headers using BeforeNavigate2
IE Addon 
Zhiqing Wan




Posts: 5
Joined: 2011-08-30
Hi,

i am stuck with a problem. I need to add custom http request header for every request in IE, for example: "ABCSession: asdfjsdfjsdj". I am using:

this.BeforeNavigate2 += new IE.DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate2);

public void
OnBeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel)
{
Headers += "ABCSession: asdfjsdfjsdj" + "\r\n";
}

But this custom header is evetually not added to any http request.

I use the this.BeforeNavigate2 += new ADXIEBeforeNavigate2_EventHandler(OnBeforeNavigate2);

Also doesn't help...



Who can help me?

Zhiqing
Posted 30 Aug, 2011 05:57:47 Top
Sergey Grischenko


Add-in Express team


Posts: 7228
Joined: 2004-07-05
Hi Zhiqing,

As far as I know, there is a bug in the BeforeNavigate2 method of the IE object model. Please try to use the Stop method to interrupt the navigation and then re-open the url using the Navigate2 method. It should help.
Posted 30 Aug, 2011 11:13:59 Top
Zhiqing Wan




Posts: 5
Joined: 2011-08-30
Hi Sergey,

thanks for the help. I've also read one post saying BeforeNavigate2 has a bug in C#. But i might try with C++ afterwards.

I have another question. I designed an Addon. There is a button on it. When I click the button, other opened tabs or IE windows should be closed. That means only one IE tab is allowed to be open after clicking this button. Do you have any idea how to imeplement this?

Thanks,
Zhiqing
Posted 31 Aug, 2011 08:08:07 Top
Sergey Grischenko


Add-in Express team


Posts: 7228
Joined: 2004-07-05
Hi Zhiqing.

You can use the SendMessageToAll method to send a custom message to all instances of your add-on (except for the current one) and then you need to call the IE.Quit method in the OnSendMessage event handler.
Posted 01 Sep, 2011 05:38:26 Top