【问题标题】:ASP.NET TableStorageProvider for Azure tables not persisting users?Azure 表的 ASP.NET TableStorageProvider 没有持久化用户?
【发布时间】:2010-09-09 08:31:16
【问题描述】:

我有一个在 WCF+ASP.NET 之上使用 Silverlight 的 Windows azure Webrole 应用程序。我在Azure samples 中找到了这个用于 Azure 表的有用 ASP.NET 提供程序并实现了它。我使用 WCF 服务 System.Web.ApplicationServices.AuthenticationService 对我的用户进行身份验证。

效果很好:我用一个非常简单的 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 并重新创建一个用户,它就可以正常工作。

【问题讨论】:

  • 你确定表存储的所有Membership和Roles表中都有用户的数据吗?开发人员存储中存在一个错误,当存在空的 Table Storage 表并对它们进行查询时,该错误在重新启动之前不会显现出来。
  • 我刚刚启动了我的机器并检查了表格。 Membership、Roles 和 Sessions 中都有数据。这就是我担心的问题:如果它是一个开发存储错误(在这种情况下它不是问题),或者它是一个 Provider-Azure 错误(更烦人......)
  • Azure 示例不应该是生产代码,我还在考虑是否使用它们:(

标签: c# asp.net azure membership-provider


【解决方案1】:

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

【讨论】:

  • 感谢您的回答,即使这个项目已经结束将近一年了!
猜你喜欢
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 2014-09-02
  • 2016-12-31
  • 2016-06-24
  • 1970-01-01
  • 2016-02-27
相关资源
最近更新 更多