Silverlight用户身份验证

Tob*_*orn 7 security authentication silverlight silverlight-3.0

我目前正在开发需要某种用户身份验证的Silverlight 3应用程序,因为从WCF服务提取的数据是特定于用户的.目标受众是常规互联网 - 因此没有AD可以进行身份​​验证.

以下是我对这种情况的一些问题:

  • 是否有支持我的框架或其他机制?
  • 您是否会建议在Silverlight应用程序内或通过表单身份验证等外部机制进行身份验证?哪个更安全?
  • 浏览器外支持怎么样?

R4c*_*OOn 2

我使用了ASP.NET的身份验证。只需使用 MembershipProvider (或实现您自己的)。然后转至http://www.silverlightshow.net/items/Accessing-the-ASP.NET-Authentication-Profile-and-Role-Service-in-Silverlight.aspx查看如何公开身份验证服务。

然后在 WCF 服务中执行以下操作(托管在 ASP 中):

public class MyWCFService : IMyWCFService 
{
        // retrieve your UserId from the MembershipProvider
        private int GetUserId()
        {
            MembershipUser user = Membership.GetUser();
            int userId = (int)user.ProviderUserKey;
            return userId;
        }

        // check if user is authenticated
        private bool IsUserAuthenticated()
        {
            return HttpContext.Current.User.Identity.IsAuthenticated;
        }

        public void Subscribe()
        {
            if (!IsUserAuthenticated())
            {
                throw new SecurityException("You must be authenticated to be able to use this service.");
            }

            int userId = GetUserId();
            DoStuff(userId);
        }
}
Run Code Online (Sandbox Code Playgroud)

希望有帮助。