Fill a session variable from windows app using web browser control

白昼怎懂夜的黑 提交于 2019-12-25 06:34:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!