Hello,
Welcome to our Microsoft Q&A platform!
You can set a cookie in Webview
of Xamarin Forms, you must create a custom-renderer for Webview
like following code.
[assembly: ExportRenderer(typeof(WebView), typeof(CustomWebViewRenderer))]
namespace WebViewTest.Droid
{
public class CustomWebViewRenderer : WebViewRenderer
{
public CustomWebViewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.Settings.JavaScriptEnabled = true;
var webViewClient = new CustomWebViewClient();
Control.SetWebViewClient(webViewClient);
CookieManager cookieManager = CookieManager.Instance;
if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
{
CookieSyncManager.CreateInstance(Control.Context);
}
cookieManager.SetAcceptCookie(true);
cookieManager.RemoveSessionCookie();
cookieManager.SetCookie("http://xx.example.com", "mid=" + MySession.GetSession().sessionId + " ; Domain=.example.com");
//get the cookie
string cookie = cookieManager.GetCookie("http://xx.example.com");
}
}
If you have issue about creating identity AspNetCore.Cookies, please open a new thread in the asp.net forum.
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.