2011-03-13 77 views
1

我已经实现了RIA WCF端以使用Forms身份验证进行身份验证,并且所有工作都可以在客户端上按预期进行。Silverlight RIA仅接受注册用户的应用程序

此应用程序应该只允许注册用户使用它(用户由admin创建 - 没有注册页面)。

我的问题是,什么(或哪里)应该是进行认证的有效方式;它必须在应用程序启动时显示(除非记住我已启动并且cookie仍处于活动状态),并且如果用户注销,它应该自动退出界面并再次返回登录表单。

更新(代码修整为简洁起见):

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 
+0

是你使用mvvm? – 2011-03-13 06:54:52

回答

2

我看到你的其他问题,所以我假设你使用MVVM。我通过创建一个具有网格控件和导航框架的RootPage来完成此任务。我将RootVisual设置为RootPage。我将导航框架源绑定到RootPageVM中的变量,然后在RootPageVM的consructor中,您可以将框架源设置为基于用户身份验证的MainPage或LoginPage。 RootPageVM还可以接收消息来控制进一步的导航,如注销。

使用MVVM-Light。

所以,在RootPageView(设置为RootVisual),是这样的:

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

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

而对于导航的方法:

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

在LoginViewModel:

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

@Derek,+1,你开始好,请详细说明。 – Shimmy 2011-03-13 07:25:02

+0

IDK,我应该如何创建“AuthenticationService”事件的处理程序,以及如何在UI中管理它;当他未经认证时,我需要立即将用户踢出去。该程序仅用于为注册用户提供服务。用户应该看到一个错误/死亡屏幕。 – Shimmy 2011-03-13 08:31:13

+2

我在LoginViewModel中有逻辑,如果用户进行身份验证,我会发送一条将在RootPageViewModel中收到的消息,告诉它导航到MainPage。您可以在注销时执行相同的操作,发送消息导航回LoginPage。 – 2011-03-13 16:11:53

相关问题