locked
[WP8.1][C#]Beginner Windows Phone 8.1 C# Development(Webview) RRS feed

  • Question

  • Hello everyone I am currently developing a C# Windows Phone 8.1 application in Visual Studios community 2015. I'm at the end of this project, and it seems I may have some trouble saving passwords while in Webview. What I want is for when the user enters there user name and password then proceeds to exit that Webview and then opens it back up their credentials are already there to login again. I'm not sure how to go about doing this being that there is no:

    .SaveEnabled

    for Windows Phone 8.1 applications. Any hints to how I can achieve my goal will be helpful. Thank You.


    Thursday, March 31, 2016 2:45 PM

Answers

  • Hi Oneil M,

    >>” What I want is for when the user enters there user name and password then proceeds to exit that Webview and then opens it back up their credentials are already there to login again.

    I think you could use “WebView.NavigateWithHttpRequestMessage”. This method navigates the WebView to a URI with a POST request and HTTP headers.

    There is an article about “WebView Single-Sign On” which include the following code, the link is https://blogs.msdn.microsoft.com/wsdevsol/2013/10/31/webview-single-sign-on/ :

    Prior to Windows 8.1, we couldn’t really get WebView to work without a prompt for credentials when accessing a website protected by Basic Authentication.  However, WebView 8.1 provides a new method which makes this easy: NavigateWithHttpRequestMessage.

    The use of this method allows us to add headers to an outgoing HTTP request.  What we do to use Basic Authentication is to Base-64 encode the username/password, then pass that information into the NavigateWithHttpRequestMessage.  Here’s source code for making this work:

    Windows.Web.Http.HttpRequestMessage httpRequestMessage = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Get, new Uri("http://servername/index.html"));
    httpRequestMessage.Headers.Add("Authorization", "Basic " + CryptographicBuffer.EncodeToBase64String(CryptographicBuffer.ConvertStringToBinary("username:password",BinaryStringEncoding.Utf8)));
    WebView1.NavigateWithHttpRequestMessage(httpRequestMessage);

     It’s important to note that the Header information must be formatted in exactly the way shown in order for the server to recognize it.

    Best Regards,

    guang9Bear


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, April 1, 2016 9:05 AM