Search code examples
c#ms-accessasp.net-membershipvisual-studio-expressvisual-web-developer

Use currently logged-in user in query


I am using VisualWebDeveloperExpress2008 with Access as the membership provider.

I have some cases where I want users to edit their own data. This would involve a query where the UserId should equal the UserID of the user who is using the site.

I am expecting to use WHERE UserId = ?, but I have not found out where to direct "?".

The IDE gives several choices, but I am uncertain which to choose. This, while it looks promising does not work:

<SelectParameters>
    <asp:ProfileParameter Name="UserID" PropertyName="UserId" Type="Int32" />
</SelectParameters>

What is best to use for the Select Parameter?


Solution

  • Try using

    <SelectParameters>
        <asp:SessionParameter Name="UserName" SessionField="CurrentUser" Type="String" />
    </SelectParameters>
    

    On the Page_Load insert the following...

    Session["CurrentUser"] = User.Identity.Name;
    

    This should work for you.