简体   繁体   English

使用WCF RIA在SilverLight中实现登录

[英]Implement a login in SilverLight with WCF RIA

I create a login page with SilverLight. 我使用SilverLight创建一个登录页面。 But when users log in and then refresh page, the user is logged out! 但是,当用户登录然后刷新页面时,该用户已注销! In other words, the SilverLight application restarts. 换句话说,SilverLight应用程序将重新启动。 How can I prevent this from happening on refresh? 如何防止这种情况在刷新时发生?

I had also the same problem and after that I found some thing like this. 我也遇到了同样的问题,之后我发现了类似的问题。

I create two pages With Login page and Dashboard Page.Here is the my Login page code. 我用登录页面和仪表盘页面创建两个页面,这是我的登录页面代码。 this will help you. 这将为您提供帮助。

    private void BtnLogin_Click(object sender, RoutedEventArgs e)
    {
        user.Username = TxtUsername.Text;
        user.Password = TxtPassword.Password;

        YourReference.YourReferenceServiceClient Service = new YourReferenceServiceClient();
        Service.LoginCompleted += Service_LoginCompleted;
        Service.LoginAsync(user);
    }

    void Service_LoginCompleted(object sender, LoginCompletedEventArgs e)
    {
        if (e.Result == true)
        {
            Dashboard UserDashboard = new Dashboard(user);
            this.Content = UserDashboard;
        }
        else
        {
            MessageBox.Show("Error Occured");
        }
    }

In WCF RIA service I created a method named as Login, Here is that code. 在WCF RIA服务中,我创建了一个名为Login的方法,这是该代码。

public bool Login(User LogUser)
{
    bool Status = false;

    //......Your Code.... if it is success return True otherwise false//

    return Status;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM