【发布时间】: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