Accessing WebView cookies in WinRT

In my recent Windows 8.1 app project I needed to take advantage of ASP.NET Identity to authenticate in my ASP.NET Web API service. Because Identity offers social (external) logins on top of classic login flow, I decided to integrate them as well. Unfortunately the authentication process required the use of cookies, which needed to be forwarded to the registration endpoint to complete the registration process of a new user. Because the process itself is initiated in a WebView control, we need to obtain the resulting cookies. But WebView does not expose any properties to access them. What can we do?

It turns out it is possible to access the collection of cookies globally, without direct access to the WebView control. First step is to create an instance of the HttpBaseProtocolFilter class and access its  CookieManager property. HttpCookieManager has a few useful methods:

  • GetCookies – returns a  HttpCookieCollection of cookies associated with a given URI
  • SetCookie – sets a cookie
  • DeleteCookie – deletes a cookie

To list all the cookies associated with our URI we can then just enumerate the HttpCookieCollectionwe get from GetCookies method:

One Reply to “Accessing WebView cookies in WinRT”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

*