我目前正在使用 RIA 服务试用 Silverlight。我正在实现一个简单的登录表单。我还使用了提供的身份验证域服务模板,该模板生成以下文件:
[EnableClientAccess]
public class AuthenticationDomainService : AuthenticationBase<User>
{
// To enable Forms/Windows Authentication for the Web Application,
// edit the appropriate section of web.config file.
}
public class User : UserBase
{
// NOTE: Profile properties can be added here
// To enable profiles, edit the appropriate section of web.config file.
// public string MyProfileProperty { get; set; }
public int DefaultRows { get; set; }
}
现在我可以在我的应用程序中毫无问题地登录/注销。在 Silverlight 应用程序中,登录后,该行:
WebContext.Current.User.IsAuthenticated;
返回真。
但是,我需要在会话中坚持这一点(即,当我使用 F5 重新加载页面时)。
目前,当页面重新加载时,我必须重新登录。
这是我的登录代码:
WebContext.Current.Authentication.Login(new LoginParameters(this.UserName, this.Password, true, string.Empty),
(LoginOperation loginOperation) =>
{
if (loginOperation.LoginSuccess)
{
NotificationMessage Message = new NotificationMessage(this, null, "CLOSE");
Messenger.Default.Send<NotificationMessage>(Message);
}
}, null);
Login 方法的第三个参数是 IsPersistent 参数。从 MSDN Docs 中,我认为将其设置为 true 时,下次加载页面时,用户仍然会登录。但是,事实并非如此。
Do I somehow need to read a cookie which has been set internally and then login in the background with the username/password provided by that cookie? Or is there some other magic at work here?
I hope somehow has already done this.
Thanks in advance