You are currently viewing the BOOK: Professional ASP.NET 2.0 Security, Membership, and Role Management ISBN: 978-0-7645-9698-8 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
hello, i'm using the default db with visual studio 2005 the aspnetdb but ther's a bug in visual studio when i use sqldatasource to the aspnt_users table i only find the view of the table not the base table, so i dont know what i shoud do to manage my accounts i only want to delete accounts nothing else.thanks
hello stefsch, thanks for ur helpful reply i did what u said and it worked but i still have the delete problem i cant choose it from the datasource cos i have only the view of the table should i add it also in the source view, and another something in the admin tool when u manage users delete user for example the user deleted from the aspnet users and the aspnet membership so i think i will have a problem when i will try to delete the user from the aspnet users!! what do u think? , waiting for ur reply. thanks
You can do the same trick - set everything up against the view, and then in source switch it over to the real table name.
You are correct that deleting a user this way through the datasource is a problem. Fundamentally Membership is not a directly data-bindable feature. Usually what we recommend is:
1. Use ObjectDataSource - *not* SqlDataSource.
2. In App_Code, write a really simple class with static (in VB Shared) Select, Insert, Update, Delete methods that internally call into Membership. The reason for this is that the Membership type itself does not have all the necessary method signatures expected by ObjectDataSource to show up in the the data source wizard. As a result, you need a type in App_Code so the wizard can find it. Although this approach is more work - it does allow you to route update, insert and delete operations through the Membership provider. Which automatically takes care of things like deleting rows from tables in the correct order.
hello Stefan, thanks for ur reply but i didnt know how to do what u said i'm kind a beginner, i working in admin page the users page which i can manage my accounts i dont know if i should delete the account or lock it but to do that i will use the membership table not the aspnet users table, one last thing could u plzzz write an example code a small one just to make it clear to me. thanks for the help
Ok - this is C# code showing how to see a list of users, and then click on one of the rows in a GridView to delete a user.
First, in App_Code, create a class with the following code:
public static class MembershipWrapper
public static MembershipUser GetUser(string username)
public static bool DeleteUser(string username)
public static MembershipUserCollection GetAllUsers()
Then create a web page, and in the .aspx place the following markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
hello Stefan, it worked(yeeessss:)) u are a real genius, now i can delete users from the table, there's some columns i dont need it to appear in the gridview i will do that from the edit columns no problem, just one little thing u add the user name field from the aspnet users and the datasource deals with aspnet membership what i should do to add another columns from the aspnet users? i tried to put a tag like that <asp:BoundField DataField="UserName" HeaderText="UserName" ReadOnly="True" SortExpression="UserName" />
and changed the "username" with the column i want but it didnt work it says that "A field or property with the name 'name' was not found on the selected data source" ?!! waiting for ur reply. thanks for all that help
Since the grid is binding to an ObjectDataSource, it is actually rendering the properties on MembershipUser - *not* columns from a table like aspnet_Users.
The example below has all of the properties from MembershipUser - so there isn't anything more that can be added. The only important data from aspnet_Users are really the UserName and LastActivityDate columns. Those are available as properties on MembershipUser. The other columns in aspnet_Users are either not used by ASP.NET (i.e. MobileAlias) or not relevant (i.e. IsAnonymous).
The reason why I bound ObjectDataSource to MembershipUser is that the Membership feature is usually what you want to use for managing accounts.