launching Browser with cookies

G

Guest

Hello: I have smart client app which needs to access a "forms authentication"
protected website for certain functions. Thre credentials used to login to
smart client are the same as the credentials used to logon to website. Once
the user logs on to the client I do not want them to logon again into the
website.
I guess I have two options
a. Do a screen scraping capturing the view state of the login page and
establish the session by storing the cookies.
b. Create a webservice to logon and store the cookies and then call the urls
from a webbrowser.

Option "b" was better and so I wouldl want to proceed in this direction.

Since I would like to render html in a browser instantiated from the smart
client I cannot use standard managed classes like webclient, webresponse etc
and
need to depend on unmanaged code using shdocvw and axwebbrowser.

Now the challenge is how do I pass cookies stored in a cookiecontainer to
the Navigate or Navigate2 methods as headers so that I can access a
protected site and use the same session.
 
N

Nicholas Paldino [.NET/C# MVP]

sd,

Just to let you know, what you are describing is not a smart client.
From what I can read, it is just a web application.

And it seems like the entire application is an HTML one, so what are you
trying to do with the screen scraping and whatnot? It doesn't make much
sense.

Why not expose your functionality through web services, and then have
the smart client make calls to the web services? You can layer
authentication on top of that.

Hope this helps.
 
G

Guest

Thx for the reply, but your guess is way off the target. In my case a smart
client is being used for data entry however extensive reporting is being done
only thru webforms on the website. Since tha data is shared by multiple smart
clients, and a ultra thin interface(asp.net) is also being developed which
is being used only for reports. The smart client does communicate thru
webservices for data sync, however there is absolutely no justification in
developing reports in multiple places i.e. winforms as well as webforms and
hence this query.

As mentioned in my previous post when the user logs on to the app, he is
authenticated thru webservices and data is synced, but when he would want to
run the reports I would like to redirect him to a website.

sd.


Nicholas Paldino said:
sd,

Just to let you know, what you are describing is not a smart client.
From what I can read, it is just a web application.

And it seems like the entire application is an HTML one, so what are you
trying to do with the screen scraping and whatnot? It doesn't make much
sense.

Why not expose your functionality through web services, and then have
the smart client make calls to the web services? You can layer
authentication on top of that.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

sd said:
Hello: I have smart client app which needs to access a "forms
authentication"
protected website for certain functions. Thre credentials used to login to
smart client are the same as the credentials used to logon to website.
Once
the user logs on to the client I do not want them to logon again into the
website.
I guess I have two options
a. Do a screen scraping capturing the view state of the login page and
establish the session by storing the cookies.
b. Create a webservice to logon and store the cookies and then call the
urls
from a webbrowser.

Option "b" was better and so I wouldl want to proceed in this direction.

Since I would like to render html in a browser instantiated from the smart
client I cannot use standard managed classes like webclient, webresponse
etc
and
need to depend on unmanaged code using shdocvw and axwebbrowser.

Now the challenge is how do I pass cookies stored in a cookiecontainer to
the Navigate or Navigate2 methods as headers so that I can access a
protected site and use the same session.
 
H

hsuntn

Hi sd,

I'm facing the exact same issue. I have a C# client which communicates
primarily with a web service for data and authentication. But I also
have previously developed ASP.NET material which I want to use by
pulling up
an AxWebBrowser, and I don't want my client to have to login again.
Have you found a way to put cookies into these components so that
Sessions are shared between the smart client and the web material?
If not, I will continue to look and let you know if I find a solution.

Thanks,
Harold
Primary Global Research, LLC
 
S

Shane DeSeranno

Why are you using the AxWebBrowser? Why not use the .NET WebRequest
class to make a web request? It supports various authentication as well
as the ability to persist cookies in a CookieCollection.

I don't have an example readily available, but I'm sure if you search
for: WebRequest, CookieCollection, and C#

You can find some good stuff!
=Shane DeSeranno
 
H

hsuntn

Hi Shane,

You're exactly right, I have looked at the HTTPRequest and it seems
like it would be easy to attach cookies to it. I can certainly do this
for the initial request. However, I'm using the browser for two
things, I guess:

1) to render the returned HTML;
2) the returned page will have links on it; I'd have to trap the
link clicked event so that I can always make a cookie-laden HTTPRequest
on the browser's behalf. I'm not sure if this is possible (it may very
well be, I'm just not that familiar with the AxWebBrowser event API).

So I thought it would be easiest just to store the cookies in the
browser and have it handle everything itself.

Harold
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top