在整个MVVM Silverlight应用程序中保留FormsAuthentication用户

时间:2013-02-26 01:52:23

标签: silverlight authentication cookies mvvm formsauthentication

我需要退一步并重新开始......我想根据用户登录,通过我的ViewModel在comboBox中加载值。我使用FA这是最好的方法吗?我可以直接从ViewModel访问cookie吗?

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
user,
DateTime.Now,
DateTime.Now.AddDays(30),
false,
"Role One",
FormsAuthentication.FormsCookiePath);
// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);

// Create the cookie.
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName,
encTicket));
// Show the Silverlight control
Response.Redirect("Default.aspx");

1 个答案:

答案 0 :(得分:0)

答案很简单。只需添加对

的引用
string[] cookies = System.Windows.Browser.HtmlPage.Document.Cookies.Split(';');