2009-07-12 225 views
7

我目前正在開發一個需要某種用戶認證的Silverlight 3應用程序,因爲從WCF服務中提取的數據是用戶特定的。目標受衆是常規的互聯網 - 所以沒有AD進行身份驗證。Silverlight用戶認證

這裏有一些我有一個關於這種情況的問題:

  • 是否有一個框架或其他機制,支持我嗎?
  • 你會推薦Silverlight應用程序內的驗證或通過外部機制,如表單驗證?哪個更安全?
  • 瀏覽器支持怎麼樣?

回答

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); 
     } 
} 

希望有所幫助。

2

我會考慮使用ASP.NET中存在的身份驗證類。然後,您可以使用.NET RIA服務(或者簡單地說,WCF)與身份驗證服務進行通信。

Consider this article as a primer.

+0

您有使用此解決方案的經驗嗎? – 2009-07-13 14:49:17

+0

是的。我使用SL3和.NET RIA服務。這是我正在開發的概念應用程序的證明,但我可以遠程創建和登錄用戶。 – billb 2009-07-13 15:11:42