我目前正在开发需要某种用户身份验证的Silverlight 3应用程序,因为从WCF服务提取的数据是特定于用户的.目标受众是常规互联网 – 因此没有AD可以进行身份验证.
以下是我对这种情况的一些问题:
>是否有支持我的框架或其他机制?
>您是否建议在Silverlight应用程序内或通过表单身份验证等外部机制进行身份验证?哪个更安全?
>浏览器外支持怎么样?
解决方法
我使用了ASP.NET的身份验证.只需使用MembershipProvider(或实现自己的).
然后转到 http://www.silverlightshow.net/items/Accessing-the-ASP.NET-Authentication-Profile-and-Role-Service-in-Silverlight.aspx以查看如何公开身份验证服务.
然后转到 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); } }
希望有所帮助.