问题
I have two WinRT apps which request same Login service for a session. There is a global HttpClient(along with a cookiecontainer) in each of the apps which saves the cookie for further requests.
Currently if a user logs into app A and opens App B, the user has to login again(Even if the session has not timed out).
I do not want the user to login again if he has logged into one app. How can I achieve this? How can I share this HttpClient object across apps?
Edit: Sessions are being maintained by Cookies. How can I save the cookies(along with timeout value) on the client side in such a way that it can be accessed by the other apps?
回答1:
This will be difficult to share cookie/creds across multiple apps. One thing you can do is explore using the CredentialLocker for some of this information. In Windows 8.1, if you are using the standard authentication brokers, the credential information can be saved for the provider (user opt-in) to make it easier for AppB to login the second time (not automatically, but would pre-fill creds)
回答2:
Impliment a Cookie Mechanizem like http://en.wikipedia.org/wiki/HTTP_cookie
for example when user logins to app save in registry username and randomly generated GUID save the same GUID in the server along with expire date.
every time a user tries to login check in registry for Cookie entry and if found send to the server your username and GUID if GUID is valid and cookie not expired allow login.
来源:https://stackoverflow.com/questions/18041875/common-login-for-multiple-winrt-apps