如何在Xamarin WebView中访问cookie? [英] How do I access cookies in a Xamarin WebView?

查看:298
本文介绍了如何在Xamarin WebView中访问cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的Xamarin应用中,我们需要允许我们的用户使用他们自己的SSO解决方案登录.

In our Xamarin app, we need to allow our users to log in using their own SSO solution.

这在我们的iOS应用程序中的工作方式是,我们打开一个具有网络视图的控制器,并将其指向我们的网站,并一直监视着这些cookie,直到它们回到cookie并指示它们已经回到我们的网站上为止.重新登录.但是在Xamarin中,我看不到如何访问WebView的cookie.我们的Xamarin应用程序可在Windows 8.1和WinPhone 8.1上运行,但有时会扩展到Android,因此我需要一个跨平台的解决方案.

The way this works in our iOS app is that we open up a controller with a web view and point it at our site, and keep watching the cookies until they're back on our site with the cookie that indicates that they're logged in. But in Xamarin, I can't see how I can access the cookies for the WebView. Our Xamarin app is running on Windows 8.1 and WinPhone 8.1, but it will be extended to Android at some point so I need a cross-platform solution.

那么,如何在Xamarin WebView中访问cookie?

So, how do I access cookies in a Xamarin WebView?

推荐答案

您需要在PCL-Project中创建一个自定义控件,然后为每个平台添加一个自定义的webview.然后,平台特定的实现将获得成功,您可以从pcl-webview中使用它.

You need to create a custom control in your PCL-Project and then add a custom webview for each platform. The platform secific implementation then gets the coockies and you can use it from your pcl-webview.

在Android上,您可以使用以下代码获取Cookie:

On Android you can get the cookies with following code:

var cookieHeader = CookieManager.Instance.GetCookie(url);

在iOS上:

NSHttpCookieStorage storage = NSHttpCookieStorage.SharedStorage;

github上的源代码: https://github.com/seansparkman/CookiesWebView

Sourcecode on github: https://github.com/seansparkman/CookiesWebView

这篇关于如何在Xamarin WebView中访问cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆