如何将当前用户的Id用作asp页面中查询的参数?
我使用MySQL作为会员和角色的提供者,因此应该能够访问当前用户的用户ID。
我想做这样的事情,但是我收到一个错误' System.Web.Profile.DefaultProfile'不包含名称为' Id'
是否在我的查询中链接到@Id的Name或PropertyName?
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnectionString %>" ProviderName="<%$ ConnectionStrings:DefaultConnectionString.ProviderName %>"
SelectCommand="SELECT Date, Distance, LongestActive, ActiveTime, Km, StepCount, SiteUserId FROM UpMoves WHERE SiteUserId = @Id AND Date BETWEEN '2013-10-01' AND '2013-10-31' ORDER BY DATE ASC">
<SelectParameters>
<asp:ProfileParameter Name="Id" PropertyName="Id" Type="Int32" />
</SelectParameters>
以下编码评论和链接我现在在Page_Load
中有以下代码 System.Web.Security.MembershipUser user = System.Web.Security.Membership.GetUser();
System.Web.Profile.ProfileBase profile = System.Web.Profile.ProfileBase.Create(user.UserName);
profile.SetPropertyValue("SiteUserId", user.ProviderUserKey);
profile.Save();
并添加到我的网络配置
<properties>
<add name ="SiteUserId" type="Int32"/>
</properties>
现在可行了
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnectionString %>" ProviderName="<%$ ConnectionStrings:DefaultConnectionString.ProviderName %>"
SelectCommand="SELECT Date, Distance, LongestActive, ActiveTime, Km, StepCount, SiteUserId FROM UpMoves WHERE SiteUserId = @SiteUserId AND Date BETWEEN '2013-10-01' AND '2013-10-31' ORDER BY DATE ASC">
<SelectParameters>
<asp:ProfileParameter Name="SiteUserId" PropertyName="SiteUserId" Type="Int32" />
</SelectParameters>
但我不禁想到必须有一种更简单的方法 - 但也许不是。