我目前正在开发一个Silverlight 3应用程序,它需要某种类型的用户身份验证,因为从WCF服务中提取的数据是特定于用户的。目标受众是普通的互联网,因此没有需要对其进行认证的AD。
以下是我对这种情况的一些问题:
发布于 2009-07-15 12:18:07
我使用了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);
}
}希望这能有所帮助。
发布于 2009-07-12 15:49:02
我会考虑使用ASP.NET中存在的身份验证类,然后您可以使用.NET RIA (甚至简单地说,WCF)与身份验证服务进行通信。
把这篇文章当作入门读物。
https://stackoverflow.com/questions/1116271
复制相似问题