1
votes

I have implemented the RIA WCF side to authenticate with Forms Authentication and everything works from the client as expected.

This application should only allow registered users to use it (users are created by admin - no registeration page).

My question is then, what (or where) should be the efficient way to make the authentication; it has to show up at application start up (unless remember me was on and cookie is still active) and if the user logs out, it should automatically get out the interface and return to login form again.

Update (code trimmed for brevity):

Public Class MainViewModel
   ....

   Public Property Content As Object 'DP property

   Private Sub ValidateUser()
       If Not IsUserValid Login()
   End Sub

   Private Sub Login()
     'I want, that when the login returns a success it should continue
     'navigating to the original content i.e.
     Dim _content = Me.Content
     Me.Content = Navigate(Of LoginPage) 
     If IsUserValid Then Me.Content = _content
   End Sub

End Class
1

1 Answers

2
votes

I saw you other question so I assume you're using mvvm. I accomplish this by creating a RootPage with a grid control and a navigation frame. I set the RootVisual to the RootPage. I bind the navigation frames source to a variable in the RootPageVM, then in the consructor of RootPageVM you can set the frame source to either MainPage or LoginPage based on user auth. RootPageVM can also receive messages to control further navigation like logging out.

Using MVVM-Light.

So, in the RootPageView (set as the RootVisual), something like:

public RootPageViewModel()
{
    Messenger.Default.Register<NotificationMessage>
      (this, "NavigationRequest", Navigate);

    if (IsInDesignMode)
    {
    }
    else
    {               
        FrameSource = 
          WebContext.Current.User.IsAuthenticated ?
          "Home" : 
          "Login";               
    }
}

And a method for navigation:

private void Navigate(NotificationMessage obj)
{          
    FrameSource = obj.Notification;
}

In the LoginViewModel:

if (loginOperation.LoginSuccess)
{                                                           
    Messenger.Default.Send
      (new NotificationMessage(this, "Home"), "NavigationRequest");        
}