2010-09-09 62 views
0

我有一个在WCF + ASP.NET上使用Silverlight的windows azure Webrole应用程序。我在Azure samples中发现了Azure表的这个有用的ASP.NET提供程序并实现了它。我使用WCF服务System.Web.ApplicationServices.AuthenticationService对我的用户进行身份验证。Azure表的ASP.NET TableStorageProvider不持久用户?

它工作的很好:我用一个非常简单的ASP.NET表单创建我的用户,然后转到我的Silverlight应用程序并成功进行身份验证,但是当关闭Azure开发存储环境并重新启动它时,我无法登录再次,即使用户仍在Membership表中。 我调试日志记录过程中,发现当供应商执行查询表,它抛出一个异常,这个方法:

private MembershipRow GetUserFromTable(DataServiceContext svc, string username) 
    { 
     SecUtility.CheckParameter(ref username, true, true, true, Constants.MaxTableUsernameLength, "username"); 

     DataServiceQuery<MembershipRow> queryObj = svc.CreateQuery<MembershipRow>(_tableName); 

     var query = (from user in queryObj 
        where user.PartitionKey == SecUtility.CombineToKey(_applicationName, username) && 
          user.ProfileIsCreatedByProfileProvider == false 
        select user).AsTableServiceQuery(); 

     IEnumerable<MembershipRow> allUsers = query.Execute(); 
     if (allUsers == null) 
     { 
      return null; 
     } 
     IEnumerator<MembershipRow> e = allUsers.GetEnumerator(); 
     if (e == null) 
     { 
      return null; 
     } 
     // e.Reset() throws a not implemented exception 
     // according to the spec, the enumerator is at the beginning of the collections after a call to GetEnumerator() 
     if (!e.MoveNext()) 
     { 
      return null; 
     } 
     MembershipRow ret = e.Current; 
     if (e.MoveNext()) 
     { 
      throw new ProviderException("Duplicate elements for primary keys application and user name."); 
     } 
     return ret; 
    } 

queryObj变量包含用户条目,当我在执行过程中检查,但query外观就像它在其中一个成员中包含异常一样。最后,制作e.moveNext()时执行失败。

如果我只是删除所有的成员表和blob并重新创建一个用户,它通常工作。

+0

您确定在表存储中的所有Membership和Roles表中的用户都有数据吗?开发人员存储中存在一个错误,直到重新启动时才会显示自身,此时存在空表存储表并对其进行查询。 – 2010-09-10 02:13:01

+0

我刚启动我的机器并检查了表格。会员,角色和会话中都有数据。这就是我所担心的问题:如果它是一个开发存储错误(在这种情况下它不是问题),或者它是一个提供者 - Azure错误(更烦人......) – Paul 2010-09-10 07:57:14

+0

Azure样本不应该是生产代码,我仍在考虑是否使用它们:( – vtortola 2011-02-09 22:18:50

回答

0

来自sdk的样品不是生产准备好的。 Windows Azure Toolkit for Windows Phone 7Windows Azure Training Kit中有更新的版本。如果由于blob存储中的会话管理没有得到清除而导致在不同用户会话之间关闭浏览器,则可能在开发环境中存在问题。我们已经在我们的book中使用过它们,并且没有问题地进行测试。

+0

谢谢你的回答,即使这个项目已经过去将近一年了! – Paul 2011-05-16 09:45:29