locked
Webview authentication cookie sharing

    Question

  • I have a Webview control which loads a page and then users sign in. The webview pretty much shows everything for the app. I have also a background task which updates and gives the app a live tile. What I would like to do and I just cant seem to figure out a way is that when the background task does a Request to one of the pages Webview was showing, to use the same authentication cookies. So then the request can pull user specific data because the user is still logged in on the site and show on the app tile.

    How can i get HttpWebRequest to use the same authentication cookie that was created using Webview?

    Is there any other way I can do a request where I can use the same authentication cookie?

    Saturday, May 03, 2014 2:41 AM

Answers

All replies

  • Hi timi2shoes,

    Probably not, webview control save its cookie, cache and etc. in the folder C:\Users\<username>\AppData\Local\Packages\<PackageName>\, and currently there is no programmatic way to access it.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, May 05, 2014 8:52 AM
    Moderator
  • To reply to my own question, I found a work around that worked.

    I used InternetGetCookieEx to get the cookies from WebView then used those cookies with HttpWebRequest and its CookieContainer.

    The above solution worked great until I ran the app through the certification tool. It failed the Supported API test. I found out that InternetGetCookieEx is only part of Desktop and not part of the Windows SDK for Windows Store apps.

    Does anyone see another work around? There has to be another way.

    Monday, May 05, 2014 2:48 PM
  • Don't use HttpWebRequest.  Use HttpClient instead.  It shares the underlying WinInet stack and cookies will be shared transparently. Link: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.web.http.httpclient.aspx


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)


    Wednesday, May 07, 2014 11:29 AM
    Moderator
  • Jeff,

    I'm new to 8.1 dev (from WP8). What you're saying is that if I create a WebView, have the user log into it, and also create a new HttpClient object, the HttpClient object will have the same cookies as the WebView?

    Saturday, August 16, 2014 9:29 PM