Add header on request

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

Add header on request
how to add headers on particular request? 
pa1 modi




Posts: 84
Joined: 2011-06-18
is that possible to add headers using this

e.headers="name:ads"

IEApp.Navigate(url,flag,targetframe,postdata,e.header);
Posted 29 Jul, 2011 01:21:39 Top
Sergey Grischenko


Add-in Express team


Posts: 7229
Joined: 2004-07-05
Hi Pavan.

if i add the header by e.headers using BeforeNavigate2(ADXIEBeforeNavigate2EventArgs e) than how can i get the header data from server side as response ??

There is not any way to implement it via the IE object model.
You need to use HttpWebRequest and HttpWebResponse classes.


is that possible to add headers using this
e.headers="name:ads"
IEApp.Navigate(url,flag,targetframe,postdata,e.header);

Yes, sure.
Posted 29 Jul, 2011 09:12:50 Top
pa1 modi




Posts: 84
Joined: 2011-06-18
ok Sergey i add headers using e.headers="name:ads" on particular request.

after that how to get that header in header response ??
Posted 29 Jul, 2011 09:24:17 Top
Sergey Grischenko


Add-in Express team


Posts: 7229
Joined: 2004-07-05
The IE object model doesn't provide the Response object.
Posted 29 Jul, 2011 09:35:09 Top
pa1 modi




Posts: 84
Joined: 2011-06-18
hi Sergey ok as you told "The IE object model doesn't provide the Response object."

so if i want header response than how can i get ??

have you any example or idea for that...
Posted 30 Jul, 2011 00:45:33 Top
Sergey Grischenko


Add-in Express team


Posts: 7229
Joined: 2004-07-05
Hi Pavan.

I have just tested the code below. It works fine on my Pc.

// The add-on code.
private void button1_Click(object sender, EventArgs e)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:51145/default.aspx");
request.Method = "GET";
request.Headers.Add("MyCustomHeaderValue", "test");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

string value = response.Headers["MyResponseHeaderValue"];
if (!String.IsNullOrEmpty(value))
{
if (value.Equals("Request processed successfully."))
MessageBox.Show(this, value);
}

response.Close();
}

// The ASP.NET application code
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (this.Request.Headers.Count > 0)
{
string value = this.Request.Headers["MyCustomHeaderValue"];
if (!String.IsNullOrEmpty(value))
{
if (value.Equals("test"))
this.Response.AddHeader("MyResponseHeaderValue", "Request processed successfully.");
}
}
}
}

Another example:

// The add-on code
private void button1_Click(object sender, EventArgs e)
{
object dummy = null;
object url = "http://localhost:51145/default.aspx";
object header = "MyCustomHeaderValue:test\r\n";
this.IEApp.Navigate2(ref url, ref dummy, ref dummy, ref dummy, ref header);
}

// The ASP.NET code
protected void Page_Load(object sender, EventArgs e)
{
if (this.Request.Headers.Count > 0)
{
string value = this.Request.Headers["MyCustomHeaderValue"];
if (!String.IsNullOrEmpty(value))
{
if (value.Equals("test"))
this.Response.AddHeader("MyResponseHeaderValue", "Request processed successfully.");
}
}
}

In this case you can’t get the response in the add-on code because IE doesn’t provide such a possibility.

P.S. I sent the same code to Khatri Anand. Could you please coordinate your questions and send them by email?
Posted 01 Aug, 2011 07:31:33 Top
pa1 modi




Posts: 84
Joined: 2011-06-18
hi Sergey

have u any idea or link for block ads on I

need script or source regarding block the ads



thanks
Posted 03 Aug, 2011 06:38:15 Top
Sergey Grischenko


Add-in Express team


Posts: 7229
Joined: 2004-07-05
Hi Pavan.

No, I don't have such a link. Please try to google this issue.
Posted 03 Aug, 2011 07:19:21 Top
pa1 modi




Posts: 84
Joined: 2011-06-18
its ok

thanks actually i need to block ads for IE through programmatic..
Posted 03 Aug, 2011 07:23:29 Top
pa1 modi




Posts: 84
Joined: 2011-06-18
The ‘getElementById("tplfile")‘ statement return this url
"http://www.fanboy.co.nz/adblock/ie/fanboy-noele.tpl"

i want to load tpl file using this URL and this is javascript so please help me for use it in c#.


function loadTPFile() {
var URL = document.getElementById("tplfile").value;
var description = 'Example Tracking Protection List';
window.external.msAddTrackingProtectionList(URL, description);
}
Posted 05 Aug, 2011 08:26:35 Top