How can I maintain the authentication of a browser session when creating a new HttpWebRequest

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

How can I maintain the authentication of a browser session when creating a new HttpWebRequest
Trying to use a browsers authorized session with a new HttpWebRequest object 
Justin Ricci




Posts: 14
Joined: 2010-08-12
Hi all,

We have a forms based authentication web site (asp.net) that our users log into...
After they've been authenticated they can utilize some of the features of the BHO I'm creating with add-in-express. One of these features causes an http POST to occur. I have this working with the IEApp.Navigate function and performing 'good enough' for us, as it does create a new window, or can take over the current window. However, I was hoping to take it a step further and do the http post behind the scenes with a System.Net.HttpWebRequest. The only issue is, how can I use the session that's been authenticated with the browser already in this new request? Any ideas? Is there a piece of header information I need to utilize? I'm not sure what I'm looking for here, thanks for any help.

-Justin
Posted 26 Aug, 2010 12:24:12 Top
Sergey Grischenko


Add-in Express team


Posts: 7193
Joined: 2004-07-05
Hi Justin.

How do you perform the authentication in your form? Probably you also need to prepare a new
web request in the form and set the Credentials preperty to use for this request.
Posted 30 Aug, 2010 08:02:51 Top
Justin Ricci




Posts: 14
Joined: 2010-08-12
We're using basic forms authentication in an asp.net app. I'd imagine the session information with being stored in a cookie or something. Trying to figure that all out now, but wasn't sure if someone here may have already solved it for me!
Posted 02 Sep, 2010 12:59:23 Top
Andrei Smolin


Add-in Express team


Posts: 14210
Joined: 2006-05-11
Hi Justin,

I'm afraid we have no experience in that area. I'd suggest googling for a correct answer.

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 03 Sep, 2010 05:01:33 Top
Justin Ricci




Posts: 14
Joined: 2010-08-12
Hey Andrei, I solved the problem! Here is a link to the asp.net forum with the answer in case anyone else on here finds this question.

http://forums.asp.net/p/1598274/4071908.aspx#4071908

Basically I draw the cookie out using the comInterop for InternetGetCookieEx and if that doesn't work, I try and locate the cookie on the drive using the Environement.SpecialFolder.Co okies designator. From there I can simply attach the cookie to the httpWebRequest and we are good to go.

Thanks again!
Posted 10 Sep, 2010 14:02:52 Top
Andrei Smolin


Add-in Express team


Posts: 14210
Joined: 2006-05-11
Oh Justin, thank you so much for that link!

"Together we stand Divided we fall"

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 13 Sep, 2010 09:08:54 Top