Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 14th, 2011, 11:28 AM
Authorized User
 
Join Date: Jan 2011
Posts: 89
Thanks: 1
Thanked 0 Times in 0 Posts
Default Membership.DeleteUser(User.Identity.Name, True)

This should be a quick one, I have a button to delete a user but an additional UserDetails table retains the information so I added a FK contraint in the Database Diagrams hoping this would be removed too if it's connected to the user details but after setting that I get a YSOD when registering a user.

Whats the best way to remove this additional user data?
 
Old April 14th, 2011, 11:55 AM
Authorized User
 
Join Date: Jan 2011
Posts: 89
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I managed this manually by using:

Dim CurrentUser As String = Membership.GetUser(User.Identity.Name).ToString()

Protected Sub btnYes_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnYes.Click
Membership.DeleteUser(User.Identity.Name, True)
Dim conString As String = System.Configuration.ConfigurationManager.Connecti onStrings("ConnectionString").ConnectionString
Dim con As New SqlConnection(conString)
Dim cmd As SqlCommand = New SqlCommand("DELETE FROM UserDetails WHERE (UserName = @UserName)", con)
cmd.Parameters.AddWithValue("@UserName", CurrentUser)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
con.Dispose()

FormsAuthentication.SignOut()
FormsAuthentication.RedirectToLoginPage()
End Sub
 
Old April 15th, 2011, 02:58 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Alex,

Yes, that works well. If you want to do it the database way, search Google for "cascading delete sql server". You can link your data to the users table and define behavior for the Delete operation.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
User Instance=True dpkbahuguna ASP.NET 3.5 Professionals 6 January 22nd, 2009 11:02 AM
Chapter 4 - Membership and Identity cindeost BOOK: Beginning ASP.NET 2.0 and Databases 0 November 17th, 2008 10:55 PM
User Identity stonesbg ASP.NET 2.0 Basics 1 February 9th, 2007 11:14 AM
Crys. Report Err - identity impersonate=true rajasarkar ASP.NET 1.0 and 1.1 Professional 0 July 28th, 2006 07:15 AM
Chapter 4: Membership and Identity. (Access 2003) shirley65 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 7 March 23rd, 2006 03:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.