0
votes

I have developed a simple Xamarin Forms App( targeting IOS and Android) with just a WebView and displaying an ASP.NET website in it. It works as expected. Now, my requirement is to store the authentication cookie when user logs in for the first time and attach that cookie every time the App gets opened so that the user does not need to login each time. I have tried creating Custom WebView Render following the below code, but it doesn't seem to work for my scenario.

https://forums.xamarin.com/discussion/41039/setting-cookies-in-a-webview

I am able to access all cookies on WebView, but how do I store the necessary cookie and attach that cookie to WebView when the App gets opened again?

Any help would be appreciated.

1

1 Answers

-1
votes

android, in the onFinishLoad of the webview client:

CookieManager.Instance.Flush();

IOS:

in the onFinishLoad of the webview client to get yours cookies

(NSString)NSUserDefaults.StandardUserDefaults.ValueForKey((NSString)"CookiePZ8") ?? string.Empty

but you need to ad this line in your create of the OnElementChanged of your webview render

request["Cookie"] = (string)((NSString)NSUserDefaults.StandardUserDefaults.ValueForKey((NSString)"CookiePZ8") ?? string.Empty);
his.loadUrl(request);