IE hosted .NET control as webservice client

I

Igor Kramaric

Hi all,
here is my story:

WHAT I HAVE
I'v got a web aplication (many aspx and html pages), some of this (html)
pages host .Net windows controls (derived from
System.Windows.Forms.UserControl) inside HTML page. These controls are web
service clients on same web server, in the same web application. Webservice
is session enabled. It resides inside of the same application with my web
pages (aspx).

WHAT IS THE PROBLEM
For some reason first time control is accesing the web service new session
is created, although I was already browsing with my IE through my
application, having already one session created. It seems that control
hosted in IE can not share this session, or that is somehow not aware of it.

WHAT I WOULD LIKE
I would simply like to share the same session no matter if i'm browsing my
aspx,html pages or i'm accesing webservice from my IE hosted control.

Any advice?

Thanks,

Igor Kramaric
 
A

Adam Bieganski

WHAT I WOULD LIKE
I would simply like to share the same session no matter if i'm browsing my
aspx,html pages or i'm accesing webservice from my IE hosted control.

Igor,
I came up with the following solution, which might solve your problem.
Maybe by posting it here, I could also ask for some kind of feedback about
whether my solution is ok and doesn't actually works "by accident" only :)

Ok, here it is:

1. Move the hosted windows forms control from an html files into an aspx
file (since only in aspx you can access the session ID).
2. Embed the windows forms control in the aspx like this:
<object id="myCtl" classid="UC1.dll#UC1.UC1" width="800"
height="400" VIEWASTEXT>
<PARAM Name="sessID" Value="<%
Response.Write(Session.SessionID); %>">
</object>
3. Inside the windows forms control:
a) create a public property called sessID which will obtain the
ASPX's session ID from the <param>, and store it in a private field called
_sessID:
public string sessID {
get {
return _sessID;
}
set {
_sessID = value;
}
}
b) when calling the Web Service, do it this way:
localhost.MyWebService ws = new localhost.MyWebService();
ws.CookieContainer = new System.Net.CookieContainer();

System.Net.Cookie c = new System.Net.Cookie();

c.Domain = "localhost";
c.Name = "ASP.NET_SessionId";
c.Path = "/";
c.Value = this._sessID;

ws.CookieContainer.Add(c);

ws.MyMethod();


Now, the idea is actually to make the Web Service use the same session ID
that the aspx application uses. In your case of the aspx files and asmx (Web
Services) files residing in the same IIS's application, this should cause
both of them to be able to access the same session state.

Please respond whether the above has helped you.

Regards,
 
I

Igor Kramaric

Thank you so much,
I will have the results in next 24 hours,

I was thinking also about replacing server side code (Response.Write...)
with jscript code that sets control property giving it cookie content.

i will let you know ASAP,

Igor Kramaric
 
I

Igor Kramaric

Dear Adam,

according to first tests .....IT WORKS!!! Tommorow I'll make some further
tests.

Thanx really a lot,

Igor Kramaric

p.s. I did it through java script.
 
A

Adam Bieganski

according to first tests .....IT WORKS!!! Tommorow I'll make some further
tests.

Thanx really a lot,

I'm glad I could help :)
I'm just wondering, whether I've discovered something new, or it is
described somewhere in msdn or in KB articles, and I simply couldn't find it
there...
Could perhaps someone at Microsoft write some opinion on it here?
p.s. I did it through java script.

That's very interesting :)
Could you please send me, and the whole newsgroup, the snippet of JScript
code that does this?
I understand that this technique would then work fine in pure html, not only
aspx...?

Regards,
 
S

Steven Spits

Adam Bieganski said:
Could you please send me, and the whole newsgroup, the snippet of JScript
code that does this?

I've been following this thread too, since I want to do a similar thing...

Adam, your code rocks, thanks! I would also like to see Igor's code...

Steven

- - -
 
I

Igor Kramaric

Absoulutely yes, the code is quite simple:

I exported one property in the 'MyControl1': 'CookieContent', then I just
say:

...
function InitCookie()
{
MyControl1.CookieContent = document.cookie;
}
...


I do it when BODY fires OnLoad()

<BODY ... onload="InitCookie()">


The rest of the story is like you suggested me, I simply feed Cookie
Conatiner with this.


Igor

P.S. My pages are HTML
 
A

Adam Bieganski

I exported one property in the 'MyControl1': 'CookieContent', then I just
say:
(...)
The rest of the story is like you suggested me, I simply feed Cookie
Container with this.

Great idea to use client-side JScript to do the job :)
Thanks for sharing it.

Take care,
 

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