【问题标题】:Silverlight can´t access FormsAuthenticationSilverlight 无法访问 FormsAuthentication
【发布时间】:2013-02-15 05:40:30
【问题描述】:

我有一个 ASP.Net 登录

if (Membership.ValidateUser("User", "Password")) { FormsAuthentication.SetAuthCookie("Testuser", false); Response.Redirect("TestingAuthNewTestPage.aspx"); }

这工作正常。我进入了 Silverlight 页面。

然后,如果我想注销,我尝试使用 FormsAuthentication.SignOut(),但在我的 silverlight 应用程序中,我无法访问 FormsAuthentication?

唯一有效的方法是如果我打电话:

WebContext.Current.Authentication.Logout();

这是退出的好方法吗?或者我如何访问 FormsAuthentication 类?

谢谢

【问题讨论】:

    标签: asp.net silverlight login


    【解决方案1】:

    您也应该清除身份验证 cookie。

    FormsAuthentication.SignOut(); 
    Session.Abandon(); //Clears Sessions
    
    //This modification will Clear cookies
    HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
    cookie1.Expires = DateTime.Now.AddYears(-1);
    Response.Cookies.Add(cookie1);
    
    //Redirect to login page
    FormsAuthentication.RedirectToLoginPage();
    

    【讨论】:

    • 问题是在我的 silverlight 代码中我无法访问 FormsAuthentication 类。那是因为我使用 ASP 登录,因此没有身份验证域服务吗?
    • ASP 登录确实有身份验证服务。会有一些小问题,比如添加命名空间:P 检查你是否使用安全命名空间导入 :)
    • 我尝试添加安全命名空间,但它仍然说它无法解析符号“SignOut”。是因为它是 Silverlight 项目而不是 asp 项目吗?
    • 我想我明白了...我不能从 silverlight 调用 FormsAuthentication,因为它是 System.Web 的一部分,我不能在 silverlight 中使用它。相反,我必须有一个调用 ASP 页面的按钮,该页面具有 Logout 方法,并且该方法将具有 FormsAuthentication.SignOut() 等。social.msdn.microsoft.com/Forums/en-US/silverlightnet/线程/7c9d11f2-7cee-4f8f-a1dc-06e1c8f03062
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    相关资源
    最近更新 更多