Asp.net

使用 ASP.NET 成員資格提供程序限制對 WCF REST (webHttpBinding) 服務的訪問?

  • January 26, 2009

我在網上找到了很多關於將 ASP.NET Membership Provider 與 wsHttpBindings 一起使用的資料,但我沒有看到任何關於將其與 webHttpBindings 一起使用的參考資料。

我正在尋找一個可以在兩種情況下工作的系統:

  1. 使用者登錄到一個 asp.net 網站,該網站正在呼叫該服務。
  2. 使用者通過 REST 直接訪問服務。

這是否可以使用內置框架(即僅通過配置)?如果是這樣,我該如何配置服務?使用者如何將憑據傳遞給 REST 服務?

我找到的最好的來源是:http: //www.leastprivilege.com/FinallyUsernamesOverTransportAuthenticationInWCF.aspx

該站點還有大量關於設置 HTTP 模組以處理基本身份驗證的其他資訊(我猜你會使用它,因為它是一種標準)。

HTTP 模組身份驗證方法位於 Codeplex 上,其中包含範常式式碼和此處的所有內容:http: //www.codeplex.com/CustomBasicAuth

你的意思是ADO.NET 數據服務?

您可以為實體建構 QueryInterceptor 並限制對它的訪問。例如:

   [QueryInterceptor("foo_entity")]
   public Expression<Func<foo_entity, bool>> FilterMembership()
   {
       MembershipUser user = Membership.GetUser();
       Guid userGuid = (Guid)user.ProviderUserKey;
       return c => c.UserId == userGuid;
   }

引用自:https://stackoverflow.com/questions/481090