问题
I have a windows application that contains a web browser, after the user login using the windows app, he is redirected to a website using a web browser control.
My question is, can I send a session variable to this website?
回答1:
You can't do that directly, since Session variables live on your application server which is completely disconnected from your windows application.
What you could do is call a simple URL which sets the variable. Example:
http://www.mywebsites/session.aspx?additem=test
Then in the page session.aspx you could add the following code
HttpContext.Current.Session.Add("mykey", HttpContext.Current.Request.QueryString["additem"]);
You just have to make sure that the same session cookie is available as the user's session otherwise it would be added to a different session.
Not however that this not entirely secure as you now open up your session object for outsiders to put whatever value they want in there.
回答2:
It sounds like you are doing quasi SSO.
If the login is handled by the site itself, set a session ID (e.g. in a cookie), set the session variable on login, and identify your session (e.g. with the cookie) in subsequent interactions with the site through the app's browser control.
If the login is not handled by the site itself, then consider a cascading/secondary login against the site following the existing login step (i.e. to similarly set a session ID and be able to subsequently identify it in interactions with the site through the app's browser control).
Or consider integrating your app and your site with real SSO - e.g. Shibboleth. Look around the Web, and you find many resources on leveraging SSO with .NET.
来源:https://stackoverflow.com/questions/21579997/fill-a-session-variable-from-windows-app-using-web-browser-control