|
|
 |
| ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

July 8th, 2009, 09:15 PM
|
|
Authorized User
|
|
Join Date: Dec 2008
Location: San Antonio, TX, USA.
Posts: 26
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Want to delete all traces of a user account
Hello,
I have assembled an admin page (since someone at M$ apparently thought it would be cute to not let us use WSAT on a production server!  ).
If you have an admin role, the page consists of a drop-down list from which you can select a username (the default is your own username), which in turn pulls up that user's account (not the profile, the login stuff) in a DetailsView control. Additionally, if the selected account is not your own, a Delete button is provided. (We don't want to accidentally delete ourselves!)
I specified in ObjectDataSource1 / DELETE tab the option that says "Boolean deleteAllRelatedData", but through trial and error, I have discovered that only the Membership table record was deleted, not the Users table record. This user did not create a profile, but I am assuming if she had, then this record would not be deleted, either.
I want all traces of this user completely deleted from the system entirely.
This will then solve the problem of why my "Select User" drop-down list still shows the deleted user, even though WSAT indicates the user no longer exists. (It was DB Explorer that tipped me off about Users and Profiles tables not being affected as they should have.)
Below is the ASPX code in question....
Code:
<h1>Edit User Accounts</h1>
<!-- SELECT USER ACCOUNT //-->
<div class="bottomblueline"><asp:Label ID="Label1" runat="server" CssClass="bold" Text="Select User Name: " AssociatedControlID="ddlUserNames"></asp:Label> <asp:DropDownList ID="ddlUserNames" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="UserName" DataValueField="UserName" TabIndex="1" onselectedindexchanged="ddlUserNames_SelectedIndexChanged"></asp:DropDownList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SqlXpress %>" SelectCommand="SELECT [UserName] FROM [vw_aspnet_Users] ORDER BY [UserName]"></asp:SqlDataSource> </div>
<!-- DISPLAY USER ACCOUNT //-->
<div class="topbottompadding"><asp:DetailsView AutoGenerateRows="False" DataSourceID="ObjectDataSource1" ID="DetailsView1" runat="server" OnItemUpdating="DetailsView1_ItemUpdating" CellPadding="0" CssClass="noborderline" DefaultMode="Edit" GridLines="Horizontal" Width="100%" onitemcreated="DetailsView1_ItemCreated"><Fields><asp:BoundField DataField="UserName" HeaderText="User Name" ReadOnly="True" SortExpression="UserName"/> <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" ControlStyle-Width="250px"> <ControlStyleWidth="250px"/>
</asp:BoundField> <asp:BoundField DataField="PasswordQuestion" HeaderText="Password Question" ReadOnly="True" SortExpression="PasswordQuestion"></asp:BoundField> <asp:CheckBoxField DataField="IsOnline" HeaderText="Online?" ReadOnly="True" SortExpression="IsOnline"/> <asp:CheckBoxField DataField="IsApproved" HeaderText="Active?" SortExpression="IsApproved"/> <asp:BoundField ControlStyle-Height="100px" ControlStyle-Width="250px" DataField="Comment" HeaderText="Comment" SortExpression="Comment"> <ControlStyle Height="100px" Width="250px"/>
</asp:BoundField> <asp:BoundField DataField="CreationDate" HeaderText="Creation Date" ReadOnly="True" SortExpression="CreationDate"/> <asp:BoundField DataField="LastActivityDate" HeaderText="Last Activity Date" ReadOnly="True" SortExpression="LastActivityDate"/> <asp:BoundField DataField="LastLoginDate" HeaderText="Last Login Date" ReadOnly="True" SortExpression="LastLoginDate"/> <asp:BoundField DataField="LastLockoutDate" HeaderText="Last Lockout Date" ReadOnly="True" SortExpression="LastLockoutDate"/> <asp:BoundField DataField="LastPasswordChangedDate" HeaderText="Last Password Changed Date" ReadOnly="True" SortExpression="LastPasswordChangedDate"/> <asp:BoundField DataField="ProviderName" HeaderText="Provider Name" ReadOnly="True" SortExpression="ProviderName"/> <asp:BoundField DataField="ProviderUserKey" HeaderText="Provider User Key" ReadOnly="True" SortExpression="ProviderUserKey"/> <asp:CommandField ButtonType="Button" ShowDeleteButton="True" ShowEditButton="True" UpdateText="Save Changes"></asp:CommandField> <asp:CommandField ButtonType="Button" ShowEditButton="True" UpdateText="Save Changes"></asp:CommandField> </Fields> <CommandRowStyle CssClass="commandline"/> <FieldHeaderStyle CssClass="bold"/> <AlternatingRowStyle CssClass="gray"/> </asp:DetailsView> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetUser" TypeName="System.Web.Security.Membership" DeleteMethod="DeleteUser" OldValuesParameterFormatString="original_{0}"> <DeleteParameters> <asp:ControlParameter ControlID="ddlUserNames" Name="username" PropertyName="SelectedValue" Type="String"/> <asp:Parameter Name="deleteAllRelatedData" Type="Boolean" DefaultValue="True" /> </DeleteParameters>
<SelectParameters> <asp:ControlParameter ControlID="ddlUserNames" DefaultValue=" " Name="username" PropertyName="SelectedValue" Type="String"/> </SelectParameters> </asp:ObjectDataSource>
</div>
Any thoughts on this? Thanks in advance! 
__________________
~ Eddie McHam
|

July 9th, 2009, 07:01 PM
|
|
Authorized User
|
|
Join Date: Dec 2008
Location: San Antonio, TX, USA.
Posts: 26
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
How weird. The problem went away.
Now Membership and Users tables delete the user, as desired.
The next hurdle was getting my "Select User Name" dropdown list (and its corresponding SqlDataSource) to update itself accordingly.
Tried ddlUserNames.DataBind() in numerous places along the page's lifecycle, to no avail until I discovered DetailsView1_ItemDeleted. That finally did the trick.
So now I have a living, breathing page that lets regular users add/update/remove their own email addresses and admin users do likewise PLUS approve/disapprove/delete other users' accounts (without accidentally nailing their own).
I shall now head home after a long, grueling day.....
__________________
~ Eddie McHam
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |