Uncle also said Xamarin~android article ~ Native Landing and WebView website how to share session

Source: Internet
Author: User

Original: Uncle also said Xamarin~android article ~ Native Landing and WebView website how to share session

The thing is, we recently opened an app, mainly using Xamarin to do a login, it with the server API data communication, when the user name password to go, jump to the new activity, and in the WebView control open the service side of the HTML5 page, and H5 page some need to be authorized to access, such as User Center, my order, my goods and so on, and our landing is implemented in the original activity, after the successful landing, the server will assign a sessionid to it, and stored in the client, as the next access to the identity, While using WebView to access the page, this SessionID and the previous is different, so, before the authorization is invalid, in order to solve this problem, we need to let the native and H5 site SessionID synchronization!

Login Activity Content

 if(Msg. state = =" $")    {        varCCD =Newlist<string> (Response. Result.Headers.GetValues ("Set-cookie")); vararr = ccd[0]. Split (New Char[] {';'})[0]. Split (New Char[] {'='})[1]; Toast.maketext ( This,"sessionid="+arr, toastlength.short).        Show (); Configdata.sessionid=arr; Intent Intent=NewIntent ( This,typeof(pageactivity));     StartActivity (Intent); }

The SessionID is then written to the corresponding domain name in the page activity.

Cookiesyncmanager.createinstance (this);             = cookiemanager.instance;             " asp.net_sessionid= " + Configdata.sessionid);             var webView = findviewbyid<webview>(Resource.Id.webView);             true ;            Webview.loadurl (API);            Webview.setwebviewclient (new custwebviewclient ());

In the above code, I define a global variable to hold the current SessionID

  publicstaticclass  configdata    {        publicstatic string Get Set ; }    }

This object is static and the property is static, which means it is an object that will be initialized when the program starts!

Uncle also said Xamarin~android article ~ Native Landing and WebView website how to share session

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.