Keep user sign in In office 365 RRS feed

  • Question

  • Hello Developers I'm using Xamarin Forms I have two method to authenticate user  :

    1 : the user enter username and password 

    2 : the user can authenticate with their Office 365 account .

    for the first method when the user enter his username and password  and check if username and password existe ... 
    i do this :

                                        app.Properties["logged"] = "true";

    same for Office  but i always go back to the Authentification Page 

    this is the App.cs 

               if (this.Properties.ContainsKey("logged") && Application.Current.Properties["logged"].ToString() == "true")
                   MainPage = new NavigationPage(new MasterMenuPage());
                   if (this.Properties.ContainsKey("currentConfig"))
                       MainPage = new NavigationPage(new AuthentificationPage());
                       MainPage = new NavigationPage(new ChoixEcole());

    Thursday, April 4, 2019 9:16 AM

All replies

  • Please use the `Insert Code Block` option in the editor to paste code into your posts. Your code is hard to read without it.

    I strongly recommend you debug this yourself. Since your code is "going to the auth page" put a breakpoint on the line of code that makes this determination. Then run your code and evaluate the expression to understand why it is going down this path instead of your expected path. Given the code you posted the issue is with your `if` statement so that is the line you want to evaluate. 

    My running theory is that the left side of your logical AND is false so it falls to the `else` block. Viewing this in the debugger will make it immediately clear if this is happening. The problem, I believe, is a scoping issue. You are using `app.Properties` in the first code block. In your `if` statement on the left side of the logical AND you're using `this.Properties` but on the right side you're using `Application.Current.Properties`. I suspect `this` and `Application.Current` aren't the same thing so you're looking at the wrong properties.

    Also, I recommend that you forget this string comparison stuff. You're dealing with a boolean so unless `Properties` is defined to be a `Dictionary<string, string>` then simply use a boolean value (`true` or `false`). It eliminates the string comparison stuff.

    Michael Taylor

    Thursday, April 4, 2019 2:10 PM