Connect to session

J

Jan Kucera

Hi.
How can I join session or read Session variables if I have the SessionID
(or anything what I can supply)?

Imagine I have a external link from my webpages, which opens an application
which is expected to make requests to the server. It starts another session,
but I need to use the session from browser.
To the link I'm able to send any property the server can give me.

Thanks, Jan.
 
B

Bruno Alexandre

what a confusion you said !!!
can you simplefy what you need?

if you have website A and website B, if not in the same server they will
have diferent sessions (even if using the same name)

to send info from website A to website B use the POST or GET and them
populate the new website with the values.

example to send session("name") and session("username") from website A to
website B


website A

session("name") = "Bruno"
session("username") = "balexandre"

the link to open the new website B if you're using GET method sould be like
this

www.domainB.com/websiteBpage.aspx?un= & session("username") & "&n=" &
session("name")

in website B populate the sessions using the QueryString method

session("name") = request.querystring("n")
session("username") = request.querystring("un")
 
J

Jan Kucera

Okay sorry if I made a big confusion to you ! :)

So. Firstly I have only one site. I will make concrete examples with the
real situation I have, I just thought it will complicate everything.

User logs into the web using Windows authentication. On the web, he opens a
project. Each user has CurrentProject variable in his Session.
Now, on some page, there is link to a Word document. The Word document opens
and -using macro- is about to update its content from CurrentProject at the
web server.
I have handler/web service published to return values to the document, for
example http://myserver/getcontent.ashx. However, Word starts new session
with its request.

And thats it. At the handler I need to get the CurrentProject but I don't
have the session into which the user logged in.

I thought that I could send I don't know eg. SessionID, so the Word can ask
for http://myserver/getcontent.ashx?SessionID=id, and on the server side, I
can get the proper session and its CurrentProject.

I have no control of the request stream (thus headers) from the Word.

Is that somewhat clearer?
Jan
 
V

V

Hi Jan,

Word will always act like a new client and hence will start a new
session. I am not too sure if you can re-use a session in teh way that
you are visualizing it or not, but here is a work around:

Create a session table in the database. This way, what you can do is
when a user logs in, you can make an entry of the session (and
associated variables) in the database. Now you can pass the SessionID
or the UserID to your word document, which can pass it on to the web
service through its macro. The web service can then recreate the
session from the database.

I hope that helped.

Regards,
Vaibhav
 
B

Bruno Alexandre

now I know what you need, but that's WORD programming issue

try to add this question in microsoft.public.word.programming newsgroup,
maybe they will responde to u better that the folhs in this NG
 
J

Jan Kucera

Actually not, this is not Word issue at all and reason why I didn't talked
about Word before.

So what I need is a collection of Session objects for Application,
accessable by SessionID as a key...

I need something like Session = Application.Sessions[mySessionID];

By the way, how do I find current session count and iterate over them?
 
N

nirmal.c

Once u have sessionID , Try setting ASPNET cookie in your
application's process by Wininet call ( InternetSetCookie )

Nirmal
 
R

Robbe Morris [C# MVP]

You don't. I don't believe that is supported in ASP.NET
not unless you manage your own providers and keep
track of them in your own code.

--
Robbe Morris - 2004-2006 Microsoft MVP C#
Earn money answering .NET questions
http://www.eggheadcafe.com/forums/merit.asp





Jan Kucera said:
Actually not, this is not Word issue at all and reason why I didn't talked
about Word before.

So what I need is a collection of Session objects for Application,
accessable by SessionID as a key...

I need something like Session = Application.Sessions[mySessionID];

By the way, how do I find current session count and iterate over them?


Bruno Alexandre said:
now I know what you need, but that's WORD programming issue

try to add this question in microsoft.public.word.programming newsgroup,
maybe they will responde to u better that the folhs in this NG
 
J

Jan Kucera

Isn't that something like storing session in db?

I understand the reason why there is new session and I know how and am able
to pass session or user id to the link.

However I store quite complex and not serializable types in session. And,
this would create two concurrent sessions, which will not be synchronized.
This is bad for me.

But thanks for the idea.
Jan
 
J

Jan Kucera

So am I free to store a HttpSession array in Application object? How
expensive would be that?

Robbe Morris said:
You don't. I don't believe that is supported in ASP.NET
not unless you manage your own providers and keep
track of them in your own code.

--
Robbe Morris - 2004-2006 Microsoft MVP C#
Earn money answering .NET questions
http://www.eggheadcafe.com/forums/merit.asp





Jan Kucera said:
Actually not, this is not Word issue at all and reason why I didn't
talked about Word before.

So what I need is a collection of Session objects for Application,
accessable by SessionID as a key...

I need something like Session = Application.Sessions[mySessionID];

By the way, how do I find current session count and iterate over them?


Bruno Alexandre said:
now I know what you need, but that's WORD programming issue

try to add this question in microsoft.public.word.programming newsgroup,
maybe they will responde to u better that the folhs in this NG

--

Bruno Alexandre
(a Portuguese in Denmark)



"Jan Kucera" <[email protected]> escreveu na mensagem
Okay sorry if I made a big confusion to you ! :)

So. Firstly I have only one site. I will make concrete examples with
the real situation I have, I just thought it will complicate
everything.

User logs into the web using Windows authentication. On the web, he
opens a project. Each user has CurrentProject variable in his Session.
Now, on some page, there is link to a Word document. The Word document
opens and -using macro- is about to update its content from
CurrentProject at the web server.
I have handler/web service published to return values to the document,
for example http://myserver/getcontent.ashx. However, Word starts new
session with its request.

And thats it. At the handler I need to get the CurrentProject but I
don't have the session into which the user logged in.

I thought that I could send I don't know eg. SessionID, so the Word can
ask for http://myserver/getcontent.ashx?SessionID=id, and on the server
side, I can get the proper session and its CurrentProject.

I have no control of the request stream (thus headers) from the Word.

Is that somewhat clearer?
Jan
 
V

V

Hi Jan,

I was looking up on how to solve your problem, and came across a link
which states something that might also affect your situation. Copying
from the link:

Q: How do I use session state with web services?
A: The extra trick needed is on the caller side. You have to save and
store the cookies used by the web service. See the MSDN documentation
on HttpWebClientProtocol.CookieContainer property.

However, please note if you're using proxy object to call a web service
from your page, the web service and your page cannot share the same
session state due to architecture limitation.

This can be done if you call your web service through redirect.

The link is: http://www.eggheadcafe.com/articles/20021016.asp. This
site is really good and you may want to post your problem there and you
can be sure of a decent response.

Incidentally, I am assuming that the webservice is in the same
appdomain as your web application.

Regards,
Vaibhav
 
J

Jan Kucera

Yes, I have just the asmx file in the web project I'm thinking about.

Thank you for the link, I will read through.
Jan
 
J

Jan Kucera

It seems the CookieContainer stuff in web service will exactly do what I
need.

Posting this also in webservices groups, so hi all.

I have a web service, which is accessed using GET protocol. I'm accessing it
using Microsoft XML, 2.0 library (this is the reason for GET), by calling
xmldoc.load(http://server/myservice.asmx/helloworld?name=Xaver).

Now, this asmx file is in the asp.net web project and I need it to use
active session. I've read (thanks to Vaibhav) that the CookieContainer can
be used to get the correct session on the server side, however... I can't
(or at least I think I can't - question to XML group) modify the request
header of Microsoft's XML parser load function. I'm afraid there is no
chance packing CookieContainer into URL, is it?

So... any idea how to call the webservice with the correct session?

Thanks,
Jan.
 
V

V

Hi Jan,

I am not even sure if what I am saying would work, but just throwing
possibilities in the air. What if you used cookieless sessions, in
which case the sessionID is passed as part of the URL. Maybe then if
you included the SessionID in the webservice URL (when called from the
word doc) the session might get re-established?

Just a thought.

Regards,
Vaibhav
 
J

Jan Kucera

I also thought about this, I would try and get know.
I read about the CookieContainer in the MSDN and it seems it will do that
work. Unfortunately if nobody says I can pass it in the URL or I can modify
the request header of MSXML2, I can't use it.
Jan
 
J

Jan Kucera

Well Vaibhav, I've tried it and cookieless session does not work. Even from
the browser, the session is not restored.
I will try to manually add some session id to the request header, maybe I
found how. Just for start, do you know what tags should I have in the header
to restore the session?
Thanks, Jan.
 
V

V

Sorry Jan,

I do not, and I will not be able to look into this problem today :(

I suddenly have a lot of work at the office. Do let me know if you
manage to solve the problem; it is an interesting problem.

I will pick it up if you still haven't solved it when i am done with my
work. Hopefully, together we may be able to solve something.

Regards,
Vaibhav
 
J

Jan Kucera

Hi Vaibhav.
Thank you very much for your item.
I did some investigation on packets and found out, that all that is sent
about the session is Set-Cookie from the server and Cookie from the IE
requests, in that form:

Cookie: ASP.NET_SessioniD=[theSessionIDreturnedBySessionObject]

Which gives me very big expectations...
However the MSXML2 which I'm using .... I'm not able to set the header with
it. I found it has a bug and the cookie header must be set twice, however
this didn't help, I see still no cookie header in the request packet. :(

(Can anybody confirm that providing valid session id in the header will get
into the session on server side? What else should be present for IIS not to
require authorization again?)

Jan.
 

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

Members online

Forum statistics

Threads
473,775
Messages
2,569,601
Members
45,182
Latest member
BettinaPol

Latest Threads

Top