Translate

Thursday 29 May 2014

Disabling User Accounts in ASP.NET C-Sharp

Disable User Account in Asp.net c-sharp

introduction

This application is about disabling logged in and logged out users by entering his or her UserName, and press the button to disable user’s account or approve a user.
We going to edit and update the IsApproved column in the aspnet_Membership table of the aspnetdb.mdf database, IsApproved column is a checkbox column which means it a Boolean data type that holds true or false.
But I won’t be working with checkboxes but will use two buttons instead, one holds true another holds false.

files

Default.aspx
Default.aspx.cs
ViewChanges.aspx
Web.config

Default.aspx
Default.aspx.cs
ViewChanges.aspx

Do not forget to use the following most important namespaces

using System.Data;
using System.Data.SqlClient;
using System.Web.Security;

without these namespaces, you will get a lot of errors

Before you debug please check the following

Please note this line of coding:
System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

The part with red text that says ConnectionString you need to change it, make it same as the name of your connection string.
To see the name of your connection string go to web.config file and open it in solution explorer and look out for a coding that looks like this:

       <connectionStrings>
  <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
   providerName="System.Data.SqlClient" />
 </connectionStrings>

You see that part that says name=” ConnectionString”, if it not the same as the red text copy and paste it on the red text that I was referring to.

testing

How to test it:
Right-click the Default.aspx file choose set as start page
Press the debug button or press F5
Enter the username inside the textbox.
Now press the disable user button, the user is now inactive.
Now click view changes hyperlink to see changes made
You can also activate the disabled user.

conclusion

Watch the video of this tutorial
If you see errors in this tutorial please notify me or just leave a comment.
If my tutorial helped you just leave a thank you message, it always nice if people give a feedback, it motivates you to do more
Thanks in advance for your lovely feedback!

No comments :