Thursday, November 21, 2013

A/B Test in AspxCommerce

Installing A/B Test module from Back End:

Login with superuser /admin in AspxCommerce

1.       Install ABTest Module zip named AspxABTesting by clicking on Dashboard > Module > Install Module. Module will be Installed as AspxABTesting.




2.       Create New Portal Page as AB Test by clicking on Dashboard > Pages > New Page.





3.       Add Module AspxABTesting in AB Test Page by clicking on Dashboard > Page Modules. Select Page Named AB Test from drop down list and drag AspxABTesting Module  inside Toppane Container.



Adding  A/B Test  From Back End

I’m going to add a test for My Cart Page for different variations.
Login with superuser /admin in AspxCommerce 2.0

Go to Dashboard > AspxCommerce> ABTesting, A window will be opened as bellow.


  • To Add New A/B Test Click on New A/B Test Link as in red Circle.
  • To Edit A/B Test Click on Action > Edit Button as in red Circle.
  • To Search A/B Test Names write the name in the search Textbox and click on Search Button.

New A/B Test or Edit Button:

After Clicking on New A/B Test or  Action > Edit a window will be shown as under.

  • A/B Test: Here we can On/Off, A/B Testing.
  • Name of A/B Test: Put a Name of the test as you desired.
  • Email Notification:  Turn it On/Off to send notification for the certain changes in the system to Admin/superuser .
  • Ends on Date: Set the Date to end Testing.
  • Users in Role: Select the roles for user who can involve for this testing.
  • Original Page: Put the URL for the Original Page to test with Slash (/).
  • Variation1: Put the URL for the Variation1 to test with Slash (/).
  • Add Variation: Click on this button if you want to add more variations for the same test.
  • Note: Maximum four variations can be added.

View Button:  

After Clicking on Action > View a window will be shown as under



  • Date wise Conversion: In above chart date wise conversions are showing. It means that in which date what was the conversion rate.
  • Day: Click on this button if you want to see the status of A/B Test for the current date.
  • Month: Click on this button if you want to see the status of A/B Test for the current Month.
  • Year: Click on this button if you want to see the status of A/B Test for the current Year.

Wednesday, November 13, 2013

Comparing Two Dates formatted (mm/dd/yyyy) using jQuery

Just convert to a Date object and compare your date value to Date.now - for example:

var endDate = Date.parse('4/25/2015'); 
var currentDate = Date.now();
if (endDate >= currentDate) {
                return true;

            }        

Find today’s date formatted (mm/dd/yyyy) using jQuery

var getDateToday = new Date();
var dateFormat = getDateToday.toISOString().split("T")[0].split("-");
var dateFormatted = dateFormat[1] + "/" + dateFormat[2] + "/" + dateFormat[0];

alert('Date Today mm/dd/yyy Format : ' + dateFormatted);

Tuesday, October 29, 2013

Inserting a string inside string using SQL Server

STUFF()

The STUFF function inserts a string into another string. It deletes a specified length of characters in the first string at the start position and then inserts the second string into the first string at the start position.

Syntax:

STUFF ( character_expression , start , length , replaceWith_expression )

SELECT STUFF('JAINUL KHAN', 7, 0, ' ABDEEN');

Returns:
---------------------
JAINUL ABDEEN KHAN
---------------------

Thursday, October 24, 2013

Calling a function inside a function asynchronously using JQuery

var Test;
$(function () {

    var ServicePath = rootPath + "Services/TestService.asmx/";

    var ajxcalls = function (methodname, param, success, error) {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            cache: false,
            async: false,
            url: ServicePath + methodname,
            data: param,
            dataType: 'json',
            success: success,
            error: error
        });
    };

    Test = {
        Init: function () {
            Test.TestCheck();
        },
        TestCheck: function () {
            var isActive = false;
            var par = JSON2.stringify({ ParameterValue: value });
            ajxcall("TestIsActive", par, function (data) { isActive = data.d; }, function () { Alert('Error'); });
            Alert(isActive);
        }
    };
    Test.Init();
});


Wednesday, October 9, 2013

SQL Server 2012 FORMAT Function vs. CONVERT Function


One of the most frequently asked questions in SQL Server forums is how to format a datetime value or column into a specific date format. Here's a summary of the different date formats that come standard in SQL Server as part of the CONVERT function and the corresponding syntax using the new SQL Server 2012 FORMAT string function. Following the standard date formats are some extended date formats that are often asked by SQL Server developers, together with the corresponding syntax as well using the new SQL Server 2012 FORMAT string function.

It is worth to note that the outputs of these date formats are of VARCHAR data types already and not of DATETIME data type. With this in mind, any date comparisons performed after the datetime value has been formatted are using the VARCHAR value of the date and time and not its original DATETIME value.

The SQL statements used below to return the different date formats use the SYSDATETIME() date function. The SYSDATETIME() function returns a datetime2(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The SYSDATETIME() function used below can be replaced by the GETDATE() or GETUTCDATE() functions. The results will be the same unless the date format includes the nanosecond portion of the time.



Standard CONVERT Date Formats
Date FormatFORMAT FunctionCONVERT FunctionSample Output
Mon DD YYYY 1
HH:MIAM (or PM)
SELECT FORMAT(SYSDATETIME(), 'Mon d yyyy h:mmtt')SELECT CONVERT(VARCHAR(20), SYSDATETIME(), 100)Jun 8 2011 1:30PM 1
MM/DD/YYSELECT FORMAT(SYSDATETIME(), 'MM/dd/yy') AS [MM/DD/YY]SELECT CONVERT(VARCHAR(8), SYSDATETIME(), 1) AS [MM/DD/YY]06/08/11
MM/DD/YYYYSELECT FORMAT(SYSDATETIME(), 'MM/dd/yyyy') AS [MM/DD/YYYY]SELECT CONVERT(VARCHAR(10), SYSDATETIME(), 101) AS [MM/DD/YYYY]06/08/2011
YY.MM.DDSELECT FORMAT(SYSDATETIME(), 'yy.MM.dd') AS [YY.MM.DD]SELECT CONVERT(VARCHAR(8), SYSDATETIME(), 2) AS [YY.MM.DD]11.06.08
YYYY.MM.DDSELECT FORMAT(SYSDATETIME(), 'yyyy.MM.dd') AS [YYYY.MM.DD]SELECT CONVERT(VARCHAR(10), SYSDATETIME(), 102) AS [YYYY.MM.DD]2011.06.08
DD/MM/YYSELECT FORMAT(SYSDATETIME(), 'dd/MM/yy') AS [DD/MM/YY]SELECT CONVERT(VARCHAR(8), SYSDATETIME(), 3) AS [DD/MM/YY]08/06/11
DD/MM/YYYYSELECT FORMAT(SYSDATETIME(), 'dd/MM/yyyy') AS [DD/MM/YYYY]SELECT CONVERT(VARCHAR(10), SYSDATETIME(), 103) AS [DD/MM/YYYY]08/06/2011
DD.MM.YYSELECT FORMAT(SYSDATETIME(), 'dd.MM.yy') AS [DD.MM.YY]SELECT CONVERT(VARCHAR(8), SYSDATETIME(), 4) AS [DD.MM.YY]08.06.11
DD.MM.YYYYSELECT FORMAT(SYSDATETIME(), 'dd.MM.yyyy') AS [DD.MM.YYYY]SELECT CONVERT(VARCHAR(10), SYSDATETIME(), 104) AS [DD.MM.YYYY]08.06.2011
DD-MM-YYSELECT FORMAT(SYSDATETIME(), 'dd-MM-yy') AS [DD-MM-YY]SELECT CONVERT(VARCHAR(8), SYSDATETIME(), 5) AS [DD-MM-YY]08-06-11
DD-MM-YYYYSELECT FORMAT(SYSDATETIME(), 'dd-MM-yyyy') AS [DD-MM-YYYY]SELECT CONVERT(VARCHAR(10), SYSDATETIME(), 105) AS [DD-MM-YYYY]08-06-2011
DD Mon YY 1SELECT FORMAT(SYSDATETIME(), 'dd MMM yy') AS [DD MON YY]SELECT CONVERT(VARCHAR(9), SYSDATETIME(), 6) AS [DD MON YY]08 Jun 11 1
DD Mon YYYY 1SELECT FORMAT(SYSDATETIME(), 'dd MMM yyyy') AS [DD MON YYYY]SELECT CONVERT(VARCHAR(11), SYSDATETIME(), 106) AS [DD MON YYYY]08 Jun 2011 1
Mon DD, YY 1SELECT FORMAT(SYSDATETIME(), 'MMM dd, yy') AS [Mon DD, YY]SELECT CONVERT(VARCHAR(10), SYSDATETIME(), 7) AS [Mon DD, YY]Jun 08, 11 1
Mon DD, YYYY 1SELECT FORMAT(SYSDATETIME(), 'MMM dd, yyyy') AS [Mon DD, YYYY]SELECT CONVERT(VARCHAR(12), SYSDATETIME(), 107) AS [Mon DD, YYYY]Jun 08, 2011 1
HH:MM:SSSELECT FORMAT(SYSDATETIME(), 'HH:mm:ss')SELECT CONVERT(VARCHAR(8), SYSDATETIME(), 8)
SELECT CONVERT(VARCHAR(8), SYSDATETIME(), 108)
13:30:45
Mon D YYYY H:MI:SS.NNNNNNNAM (or PM)1SELECT FORMAT(SYSDATETIME(), 'MMM d yyyy h:mm:ss.ffffffftt')SELECT CONVERT(VARCHAR(26), SYSDATETIME(), 9)
SELECT CONVERT(VARCHAR(26), SYSDATETIME(), 109)
Jun 8 2011 1:30:45.9428675PM 1
MM-DD-YYSELECT FORMAT(SYSDATETIME(), 'MM-dd-yy') AS [MM-DD-YY]SELECT CONVERT(VARCHAR(8), SYSDATETIME(), 10) AS [MM-DD-YY]06-08-11
MM-DD-YYYYSELECT FORMAT(SYSDATETIME(), 'MM-dd-yyyy') AS [MM-DD-YYYY]SELECT CONVERT(VARCHAR(10), SYSDATETIME(), 110) AS [MM-DD-YYYY]06-08-2011
YY/MM/DDSELECT FORMAT(SYSDATETIME(), 'yy/MM/dd') AS [YY/MM/DD]SELECT CONVERT(VARCHAR(8), SYSDATETIME(), 11) AS [YY/MM/DD]11/06/08
YYYY/MM/DDSELECT FORMAT(SYSDATETIME(), 'yyyy/MM/dd') AS [YYYY/MM/DD]SELECT CONVERT(VARCHAR(10), SYSDATETIME(), 111) AS [YYYY/MM/DD]2011/06/08
YYMMDDSELECT FORMAT(SYSDATETIME(), 'yyMMdd') AS [YYMMDD]SELECT CONVERT(VARCHAR(6), SYSDATETIME(), 12) AS [YYMMDD]110608
YYYYMMDDSELECT FORMAT(SYSDATETIME(), 'yyyyMMdd') AS [YYYYMMDD]SELECT CONVERT(VARCHAR(8), SYSDATETIME(), 112) AS [YYYYMMDD]20110608
DD Mon YYYY HH:MM:SS.NNNNNNN(24h) 1SELECT FORMAT(SYSDATETIME(), 'dd MMM yyyy HH:mm:ss.fffffff')SELECT CONVERT(VARCHAR(30), SYSDATETIME(), 13)
SELECT CONVERT(VARCHAR(30), SYSDATETIME(), 113)
08 Jun 2011 13:30:45.94286751
HH:MI:SS.NNNNNNN(24H)SELECT FORMAT(SYSDATETIME(), 'HH:mm:ss.fffffff') AS [HH:MI:SS:MMM(24H)]SELECT CONVERT(VARCHAR(16), SYSDATETIME(), 14) AS [HH:MI:SS:MMM(24H)]
SELECT CONVERT(VARCHAR(16), SYSDATETIME(), 114) AS [HH:MI:SS:MMM(24H)]
13:30:45.9428675
YYYY-MM-DD HH:MI:SS(24h)SELECT FORMAT(SYSDATETIME(), 'yyyy-MM-dd HH:mm:ss')SELECT CONVERT(VARCHAR(19), SYSDATETIME(), 120)2011-06-08 13:30:45
YYYY-MM-DD HH:MI:SS.NNNNNNN(24h)SELECT FORMAT(SYSDATETIME(), 'yyyy-MM-dd HH:mm:ss.fffffff')SELECT CONVERT(VARCHAR(23), SYSDATETIME(), 121)2011-06-08 13:30:45.9428675
MM/DD/YY HH:MI:SS AMSELECT FORMAT(SYSDATETIME(), 'MM/dd/yy h:mm:ss tt')SELECT CONVERT(VARCHAR(20), SYSDATETIME(), 22)06/08/11 1:30:45 PM
YYYY-MM-DDSELECT FORMAT(SYSDATETIME(), 'yyyy-MM-dd')SELECT CONVERT(VARCHAR(26), SYSDATETIME(), 23)2011-06-091
HH:MI:SS (24h)SELECT FORMAT(SYSDATETIME(), 'HH:mm:ss')SELECT CONVERT(VARCHAR(8), SYSDATETIME(), 24)13:30:45
YYYY-MM-DD HH:MI:SS.NNNNNNNSELECT FORMAT(SYSDATETIME(), 'yyyy-MM-dd HH:mm:ss.fffffff')SELECT CONVERT(VARCHAR(26), SYSDATETIME(), 25)2011-06-08 13:30:45.94286751
YYYY-MM-DDTHH:MM:SS:NNNNNNNSELECT FORMAT(SYSDATETIME(), 'yyyy-MM-ddTHH:mm:ss.fffffff')SELECT CONVERT(VARCHAR(27), SYSDATETIME(), 126)2011-06-08T13:30:45.9428675
DD Mon YYYY HH:MI:SS.NNNNNNNAM 1SELECT FORMAT(SYSDATETIME(), 'dd MMM yyyy h:mm:ss.ffffffftt')SELECT CONVERT(VARCHAR(26), SYSDATETIME(), 130)08 Jun 2011 1:30:45.9428675PM1
DD/MM/YYYY HH:MI:SS.NNNNNNNAMSELECT FORMAT(SYSDATETIME(), 'dd/MM/yyyy h:mm:ss.ffffffftt')SELECT CONVERT(VARCHAR(25), SYSDATETIME(), 131)08/06/2011 1:30:45.9428675PM

Reference: http://pluralsight.com/training/

Tuesday, October 1, 2013

Execute a Stored Procedure Continuously For a Specific Number of Times


I have an Insert Stored Procedure an I want to execute it to 10,00,000 times to put some dummy data in my table, for this I used this….

DECLARE @Counter INT

SET @Counter = 1

WHILE (@Counter <= 1000000)
BEGIN
       EXEC [dbo].[usp_Aspx_SaveValues] 1,8,1,0
       SET @Counter = @Counter + 1
END

Friday, September 27, 2013

Bulk SMS Provider's List in Nepal

Using J-Query as a Code Behind in AspxCommerce (Open Source E-Commerce)

If you want to make your own module in AspxCommerce this technique will be helpful to you.

1. add control to your module
2. add Test.js in your module
3. in Test.js copy and paste the code as under.
4. Do all operations here as a code behind in your Asp.Net page.


 var TestPage = '';
    $(function () {    
        var ModuleServicePath = modulePath + "Services/WebService.asmx/";
        var aspxCommonObj = {
            StoreID: 1,
            PortalID: 1,
            UserName: "username",
            CultureName: "en_US",
            CustomerID: 25
        };
        TestPage = {
            config: {
                isPostBack: false,
                async: false,
                cache: false,
                type: 'POST',
                contentType: "application/json; charset=utf-8",
                data: '{}',
                dataType: 'json',
                baseURL: AspxCommerce.utils.GetAspxServicePath(),
                method: "",
                url: "",
                ajaxCallMode: "",
                error: "",
                sessionValue: ""
            },
            ajaxCall: function (config) {
                $.ajax({
                    type: TestPage.config.type,
                    contentType: TestPage.config.contentType,
                    cache: TestPage.config.cache,
                    async: TestPage.config.async,
                    url: TestPage.config.url,
                    data: TestPage.config.data,
                    dataType: TestPage.config.dataType,
                    success: TestPage.config.ajaxCallMode,
                    error: TestPage.config.error
                });
            },
            Init: function () {              
                $("#btnSaveTest").click(function () {
                    if (frm.form()) {                    
                        TestPage.SaveUpdate();                      
                    }
                });
            },
            SaveUpdate: function () {              
                this.config.method = "SaveUpdate";
                this.config.url = ModuleServicePath + this.config.method;
                this.config.data = JSON2.stringify({ aspxCommonObj: aspxCommonObj });
                this.config.ajaxCallMode = TestPage.SaveUpdateSuccess;
                this.config.error = TestPage.SaveUpdateError;
                this.ajaxCall(this.config);
            },
            SaveUpdateSuccess: function (msg) {
                csscody.info("<h2>Successful Message</h2><p>Saved successfully!</p>");            
            },
            SaveUpdateError: function () {
                csscody.error("<h2>Error Message</h2><p>Failed to save!</p>");
            }
        };
        TestPage.Init();
    });

Tuesday, September 10, 2013

A/B Testing in E-Commerce

What is A/B Testing?

A/B testing (sometimes called split testing) is comparing two versions of a web page to see which one performs better. You compare two web pages by showing the two variants (let's call them A and B) to similar visitors at the same time. The one that gives a better conversion rate wins!

What Can We Test?

Almost anything on your website that affects visitor behavior can be A/B tested. Some elements that you can easily test are:
1. Headlines
2. Sub headlines
3. Paragraph Text
4. Testimonials
5. Call to Action text
6. Call to Action Button
7. Links
8. Images
9. Content near the fold
10. Social proof
11. Media mentions
12. Awards and badges

How does A/B testing help e-commerce sites in damage control?

Sometimes when you’re apprehensive about changing your website, trying out a variation that seems to have, say, a 50-50 chance of success requires courage. After all, if the variation doesn’t get the desired response, it can cause lost leads or conversions. And if yours is a website that receives heavy traffic, that loss can accumulate and become overwhelming within a day or two.
A/B testing tools help you keep that potential damage in check. For instance, you could show the Variation page to only 20% of your visitors, while the remaining 80% of the visitors still see the Control. You test the two versions of the web page with your live visitors and see how they respond to the change. You can always change the percentage who see the variation according to your specific requirements.
You can even track your revenue while this test is going on, and see for yourself which page (Control or Variation) is performing better for your unique set of visitors. As the statistical confidence of the test is achieved (based on the number of visitors on the site), the winning page is declared.
In simple terms, you’re no longer hanging in limbo, contemplating if you should go ahead with making a permanent change to your site. You simply A/B test for a few days and get a definite answer based on facts and proven data. After all, it’s about what works for you and not what you think should work.

Areas To A/B Test For E-Commerce Websites:

Why A/B testing is so important for e-commerce websites is because their conversion goal is not some indirect metric such as leads or downloads but a direct sale.
They can measure impact of the changes they do directly in terms of revenue. If tweaking some element on website increases average order value or revenue per visitor, it gives a direct push to company’s bottom-line

Testing Area #1: Call-to-Action Buttons

The buy now button (or call-to-action button as it is often called) is perhaps the most important element that an e-commerce website should be testing. There are various reasons why your existing buy now button may not be working well.
Button color and size: Larger and brighter generally works better. See this case study where red colored link increased conversions by 53%
Button placement: TaylorGifts increased clicks on the button by 10% simply by bringing add-to-cart button and pricing closer
Button text: RIPT Apparel, an online clothing store, increased sales by 6.3% simply by changing text on their buttons to convey limited time offers

Testing Area #2: Pricing, Discounts or Shipping Strategies


Various pricing strategies can be tested to motivate the prospective window-shopper to complete a successful sale. Even though testing pricing is hard and risky, there are ways to do it right. If you setup your price test correctly, you can gain a lot of insight into your visitor behavior.
For example, you can test ideas such as:
Ending prices with .95, .97 or .99: there are various primers on psychological testing that you can read and accordingly test on your website.
Design of pricing box: the way you show pricing can have a lot of impact. Is it to the left of product image or is it to the right? Is it closer to add-to-cart button? Do you have money back guarantee written next to your pricing?


You can also test your discount or shipping strategies.
For example, SmileyCookie, an online cookie store, found out that their customer don’t care as much about free shipping or discounts, as they care about next-day shipping. In fact, just by changing the policy that they display on al pages, they managed to increase sales by 41%.

Testing Area #3: Product Display & Search Results


Which products to show on homepage? In a particular category, do you show bestsellers or do you show newest products? Which product categories to show in the menu? These are some of the questions that you can answer via A/B testing.
Visitors respond to different products differently and as a marketer it is incredibly hard to guess which mix of products will produce maximum revenue. If you think you know it all and your e-commerce website has right product mix, read this case study on Mobal, who increased total sales by 27% just by adding a new product to the mix.
Similarly, you can test the default order of search results or number of search results to show. You can even test whether product recommendations increases revenue (by making them purchase more) or decreases revenue (by confusing them with too many choices).

Testing Area #4: Checkout Page


Visitors are so close to making the purchase, yet they sometimes abandon their shopping on the checkout page.
It is like going to a supermarket, adding products and then dragging the cart towards the payment counter before simply running away towards the exit gate deciding not to purchase the stuff.
Various ideas that e-commerce websites can use to A/B test on checkout page are:
Including or excluding a trust seal/badge. Slideshop added a trust badge and increased sales by 15%, while ICouponBlog removed a trust badge and increased conversions. This shows there is no definite answer and you must A/B test.
Removing unnecessary input fields and providing overview of order. That’s exactly what ReplaceDirect tested on their checkout page and they successfully decreased cart abandonments by 25%

10 A/B Testing Tools for Small Businesses:

2.       Optimizely
3.       Unbounce
4.       Visual Website Optimizer
5.       Genetify
6.       Convert
7.       Vanity
8.       Vertster
9.       A/Bingo

Conclusion:


If you want your E-commerce website to reach its full potential you should try A/B testing to enhance its design and overall usability. The potential for improvement is vast, and testing these elements will provide clues as to how your customers perceive your brand. The result may have a dramatic impact on your bottom line, so get into the habit of testing regularly.

Thursday, August 15, 2013

Active Directory Services Step by Step


Implementing Active Directory Service in Asp.net is described in three steps
    1.     Web.Config Settings.
    2.     Source Files for Logic.
    3.     Asp.net Pages to Implement.


    1.    Web.Config :

<configSections>               
<section name="ldapConfiguration" type="Application.Security.ActiveDirectoryConfiguration" allowLocation="true" allowDefinition="Everywhere"/>
</configSections>
<ldapConfiguration
enabled="true"
pageLevelSecurityCheck="false"
server="172.18.12.15:5000"
domain="DemoSite.local"
directoryPath="DC=DemoSite;DC=local"
groupName="elixtrauser" filter="(and(objectCategory=person)(objectClass=user)(samaccountname=usertosearch))" filterReplace="usertosearch"
adminUsername="administrator"
adminPassword="admin!#@" ADConnectionString="LDAP://172.18.12.15:5000/CN=Users;DC=DemoSite;DC=local" ></ldapConfiguration>

·         enabled: This enables active directory authentication process by registering "OnAuthenticate" event in page load of login page.
·         pageLevelSecurityCheck: This indicates if the user authentication check is needed in every page level or no.
·         server: LDAP server name or IP address
·         domain: Domain name
·         directoryPath: The path of the directory where the users reside.
·         groupName: Only the indicated user group will be able to login.
·         filter and filterReplace: Used to search user in the specified directory.


<membership defaultProvider="DemoSiteSqlMembershipProvider">
<providers>
<clear/>
<add
name="ADMembershipProvider"
type="Application.Security.ADMembershipProvider"
connectionStringName="ADConnectionString" connectionUsername="DemoSite.local\administrator"
connectionPassword=" admin!#@"
attributeMapUsername="sAMAccountName"/>
</providers>
</membership>


<roleManager enabled="true" defaultProvider="ActiveDirectoryRoleProvider">
<providers>
<clear/>
<add
name="ActiveDirectoryRoleProvider"
connectionStringName="ADConnectionString"
connectionUsername="administartor"
connectionPassword=" admin!#@"
attributeMapUsername="sAMAccountName" type="Application.Security.ActiveDirectoryRoleProvider"/>
</providers>
</roleManager>

<connectionStrings>
<clear /><add name="ADConnectionString" connectionString="LDAP://172.18.12.15:5000/CN=Users;DC=DemoSite;DC=local" /></connectionStrings> 

    2.    Application.Security(Source) :

    1.    Add a C# Class Library named Application.Security
    2.    Add Refrences for  System.DirectoryServices.Protocol, System.DirectoryServices.AccountManagement
    3.    Add these .cs files in it
I.              ActiveDirectoryHelper.cs
II.             ActiveDirectorySettings.cs
III.            ActiveDirectoryConfiguration.cs
IV.           ADMembershipDataProvider
V.            ActiveDirectoryRoleProvider
VI.           ADMembeshipController
VII.          ActiveDirectoryRoleController

Codes for Above .cs files are below.

I.              ActiveDirectoryHelper.cs

using System;
using System.DirectoryServices.AccountManagement;
using System.DirectoryServices;

namespace Application.Security
{
 public class ActiveDirectoryHelper
    {

        #region Helper Methods

        /// <summary>
        /// Gets the base principal context
        /// </summary>
        /// <returns>Retruns the PrincipalContext object</returns>
        public static PrincipalContext GetPrincipalContext()
        {
            try
            {
                PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain
                    , ActiveDirectorySettings.ActiveDirectorySettingsConfig.Domain
                    , ActiveDirectorySettings.ActiveDirectorySettingsConfig.DirectoryPath
                    , ActiveDirectorySettings.ActiveDirectorySettingsConfig.AdminUsername
                    , ActiveDirectorySettings.ActiveDirectorySettingsConfig.AdminPassword);
                return oPrincipalContext;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// Gets the principal context on specified OU
        /// </summary>
        /// <param name="sOU">The OU you want your Principal Context to run on</param>
        /// <returns>Retruns the PrincipalContext object</returns>
        public static PrincipalContext GetPrincipalContext(string sOU)
        {
           // string ldapPath = "OU=Domain Users,DC=contoso,DC=com";
            string ldapPath = "OU=" + sOU + ";" +       ActiveDirectorySettings.ActiveDirectorySettingsConfig.DirectoryPath;          
            try
            {
                PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, ActiveDirectorySettings.ActiveDirectorySettingsConfig.Domain
                    , ldapPath, ActiveDirectorySettings.ActiveDirectorySettingsConfig.AdminUsername
                    , ActiveDirectorySettings.ActiveDirectorySettingsConfig.AdminPassword);
                return oPrincipalContext;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// Gets the base DirectoryEntry
        /// </summary>     
        /// <returns>Retruns the DirectoryEntry object</returns>
        public static DirectoryEntry GetDirectoryEntry()
        {
         string domainAndUserName = ActiveDirectorySettings.ActiveDirectorySettingsConfig.Domain + @"\" + ActiveDirectorySettings.ActiveDirectorySettingsConfig.AdminUsername;
            try
            {
                DirectoryEntry oDirectoryEntry = new DirectoryEntry(ActiveDirectorySettings.ActiveDirectorySettingsConfig.ADConnectionString
                    , domainAndUserName, ActiveDirectorySettings.ActiveDirectorySettingsConfig.AdminPassword);
                return oDirectoryEntry;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        #endregion

    }
}



II.            ActiveDirectorySettings.cs


using System.Configuration;

namespace Application.Security
{
  public static  class ActiveDirectorySettings
    {
   
        #region Member Variables
        //private static ActiveDirectoryConfiguration _currentActiveDirectoryConfiguration = null;
        #endregion

        #region Properties
        private static ActiveDirectoryConfiguration activeDirectorySettings = null;
     
        public static ActiveDirectoryConfiguration ActiveDirectorySettingsConfig
        {
            get
            {
                try
                {
                    if (activeDirectorySettings == null)
                    {
                        activeDirectorySettings = (ActiveDirectoryConfiguration)ConfigurationManager.GetSection("ldapConfiguration");                      
                    }
                }
                catch
                {
                }
                return activeDirectorySettings;
            }
        }    
      
     

        #endregion
    }
}


III.           ActiveDirectoryConfiguration.cs

using System;
using System.Configuration;

namespace Application.Security
{
    public class ActiveDirectoryConfiguration : ConfigurationSection
    {
        [ConfigurationProperty("enabled", DefaultValue = "true", IsRequired = true)]
        public Boolean Enabled
        {
            get
            {
                return (Boolean)this["enabled"];
            }
            set
            {
                this["enabled"] = value;
            }
        }

        [ConfigurationProperty("server", DefaultValue = "", IsRequired = true)]
        public string Server
        {
            get
            {
                return this["server"].ToString();
            }

            set
            {
                this["server"] = value;
            }
        }

        [ConfigurationProperty("domain", DefaultValue = "", IsRequired = true)]
        public string Domain
        {
            get
            {
                return this["domain"].ToString();
            }

            set
            {
                this["domain"] = value;
            }
        }

        [ConfigurationProperty("directoryPath", DefaultValue = "", IsRequired = true)]
        public string DirectoryPath
        {
            get
            {
                return this["directoryPath"].ToString();
            }

            set
            {
                this["directoryPath"] = value;
            }
        }





        [ConfigurationProperty("groupName", DefaultValue = "", IsRequired = true)]
        public string GroupName
        {
            get
            {
                return this["groupName"].ToString();
            }

            set
            {
                this["groupName"] = value;
            }
        }

        [ConfigurationProperty("filter", DefaultValue = "", IsRequired = true)]
        public string Filter
        {
            get
            {
                return this["filter"].ToString();
            }

            set
            {
                this["filter"] = value;
            }
        }

        [ConfigurationProperty("filterReplace", DefaultValue = "", IsRequired = true)]
        public string FilterReplace
        {
            get
            {
                return this["filterReplace"].ToString();
            }

            set
            {
                this["filterReplace"] = value;
            }
        }

        [ConfigurationProperty("pageLevelSecurityCheck", DefaultValue = "false", IsRequired = true)]
        public Boolean PageLevelSecurityCheck
        {
            get
            {
                return (Boolean)this["pageLevelSecurityCheck"];
            }
            set
            {
                this["pageLevelSecurityCheck"] = value;
            }
        }

        [ConfigurationProperty("adminUsername", DefaultValue = "", IsRequired = true)]
        public string AdminUsername
        {
            get
            {
                return this["adminUsername"].ToString();
            }
            set
            {
                this["adminUsername"] = value;
            }
        }


        [ConfigurationProperty("adminPassword", DefaultValue = "", IsRequired = true)]
        public string AdminPassword
        {
            get
            {
                return this["adminPassword"].ToString();
            }
            set
            {
                this["adminPassword"] = value;
            }
        }
        [ConfigurationProperty("ADConnectionString", DefaultValue = "", IsRequired = true)]
        public string ADConnectionString
        {
            get
            {
                return this["ADConnectionString"].ToString();
            }
            set
            {
                this["ADConnectionString"] = value;
            }
        }
       


    }
}


IV.           ADMembershipDataProvider.cs

using System;
using Application.Security.Entities;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using System.Collections;
using DemoSite.UserProfile;
using System.Collections.Generic;
using Application.Security.Helpers;

namespace Application.Security
{
    public static class ADMembershipDataProvider
    {         

        #region Validate Methods

        /// <summary>
        /// Validates the username and password of a given user
        /// </summary>
        /// <param name="sUserName">The username to validate</param>
        /// <param name="sPassword">The password of the username to validate</param>
        /// <returns>Returns True of user is valid</returns>
        public static bool ValidateCredentials(string sUserName, string sPassword)
        {
            try
            {
                PrincipalContext oPrincipalContext = ActiveDirectoryHelper.GetPrincipalContext();
                return oPrincipalContext.ValidateCredentials(sUserName, sPassword);
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// Checks if the User Account is Expired
        /// </summary>
        /// <param name="sUserName">The username to check</param>
        /// <returns>Returns true if Expired</returns>
        public static bool IsUserExpired(string sUserName)
        {
            try
            {
                UserPrincipal oUserPrincipal = GetUser(sUserName);
                if (oUserPrincipal.AccountExpirationDate != null)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }



        /// <summary>
        /// Checks if user exsists on AD
        /// </summary>
        /// <param name="sUserName">The username to check</param>
        /// <returns>Returns true if username Exists</returns>
        public static bool IsUserExisiting(string sUserName)
        {
            try
            {
                if (GetUser(sUserName) == null)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// Checks if user email accoung is  already exists
        /// </summary>
        /// <param name="email">The email to check</param>
        /// <returns>Retruns true of Account is locked</returns>
        public static bool IsUserEmailExists(string email)
        {
            try
            {
                DirectoryEntry entry = ActiveDirectoryHelper.GetDirectoryEntry();
                //Bind to the native AdsObject to force authentication.
                DirectorySearcher search = new DirectorySearcher(entry);
                search.Filter = "(mail=" + email + ")";
                search.PropertiesToLoad.Add("cn");
                SearchResult result = search.FindOne();
                if (null == result)
                {
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw new Exception("Error authenticating userEmail. " + ex.Message);
            }

            return true;
        }

        /// <summary>
        /// Checks if user accoung is locked
        /// </summary>
        /// <param name="sUserName">The username to check</param>
        /// <returns>Retruns true of Account is locked</returns>
        public static bool IsAccountLocked(string sUserName)
        {
            try
            {
                UserPrincipal oUserPrincipal = GetUser(sUserName);
                return oUserPrincipal.IsAccountLockedOut();
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        #endregion

        #region Search Methods

        /// <summary>
        /// Gets a certain user on Active Directory
        /// </summary>
        /// <param name="sUserName">The username to get</param>
        /// <returns>Returns the UserPrincipal Object</returns>
        public static UserPrincipal GetUser(string sUserName)
        {
            try
            {
                PrincipalContext oPrincipalContext = ActiveDirectoryHelper.GetPrincipalContext();
                UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(oPrincipalContext, sUserName);
                return oUserPrincipal;
            }
            catch (Exception ex)
            {

                throw ex;
            }


        }

        /// <summary>
        /// Gets a certain user on Active Directory
        /// </summary>
        /// <param name="roleName">seraching users in role</param>
        /// <param name="username">the username to get</param>
        /// <returns>Returns the UserPrincipal Object</returns>
        public static DemoSiteUserCollection SearchUsers(string roleName, string username)
        {
            try
            {
                DemoSiteUserCollection userColl = new DemoSiteUserCollection();
                List<UserInfo> users = new List<UserInfo>();

                PrincipalContext oPrincipal = ActiveDirectoryHelper.GetPrincipalContext();

                if (string.Empty != username.Trim())
                {
                    UserInfo obj = new UserInfo();
                    UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(oPrincipal, username);
                    if (oUserPrincipal != null)
                    {
                        obj.UserID = oUserPrincipal.Guid.Value;
                        obj.UserName = oUserPrincipal.SamAccountName;
                        obj.FirstName = oUserPrincipal.GivenName;
                        obj.LastName = oUserPrincipal.Surname;
                        obj.Email = oUserPrincipal.EmailAddress;
                        obj.IsActive = oUserPrincipal.Enabled.Value;
                        users.Add(obj);
                    }
                }
                else
                {
                    GroupPrincipal gPrincipal = GroupPrincipal.FindByIdentity(oPrincipal, IdentityType.SamAccountName, roleName);
                    if (gPrincipal != null)
                    {
                        foreach (Principal p in gPrincipal.GetMembers(false))
                        {
                            UserInfo obj = new UserInfo();
                            UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(oPrincipal, p.SamAccountName);
                            if (oUserPrincipal != null)
                            {
                                obj.UserID = oUserPrincipal.Guid.Value;
                                obj.UserName = oUserPrincipal.SamAccountName;
                                obj.FirstName = oUserPrincipal.GivenName;
                                obj.LastName = oUserPrincipal.Surname;
                                obj.Email = oUserPrincipal.EmailAddress;
                                obj.IsActive = oUserPrincipal.Enabled.Value;
                                users.Add(obj);
                            }
                        }
                    }
                }

                userColl.UserList = users;
                return userColl;

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        /// <summary>
        /// Gets all user on Active Directory located in a specific group
        /// </summary>      
        public static List<string> GetAllUsers(string sGroupName)
        {
            try
            {
                List<string> users = new List<string>();

                PrincipalContext oPrincipal = ActiveDirectoryHelper.GetPrincipalContext();
                GroupPrincipal gPrincipal = GroupPrincipal.FindByIdentity(oPrincipal, IdentityType.SamAccountName, sGroupName);

                if (gPrincipal != null)
                {
                    foreach (Principal p in gPrincipal.GetMembers(false))
                    {
                        users.Add(p.DisplayName);
                    }
                }

                return users;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        /// <summary>
        /// Gets all groups on Active Directory
        /// </summary>      
        public static List<RoleInfo> GetAllGroups()
        {
            try
            {
                List<RoleInfo> AllGroups = new List<RoleInfo>();
                PrincipalContext ctx = ActiveDirectoryHelper.GetPrincipalContext();
                GroupPrincipal qbeUser = new GroupPrincipal(ctx);
                Principal userOrGroup = qbeUser as Principal;
                userOrGroup.Name = "*";
                PrincipalSearcher searcher = new PrincipalSearcher(userOrGroup);

                // enumerate the results - you need to check what kind of principal you get back
                foreach (Principal found in searcher.FindAll())
                {
                    // is it a UserPrincipal - do what you need to do with that...
                    if (found is UserPrincipal)
                    {
                        //  ......                      
                    }
                    else if (found is GroupPrincipal)
                    {
                        RoleInfo obj = new RoleInfo();
                        obj.RoleName = found.Name;
                        obj.RoleID = found.Guid.Value;
                        AllGroups.Add(obj);
                    }
                }

                return AllGroups;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        /// <summary>
        /// Gets a certain group on Active Directory
        /// </summary>
        /// <param name="sGroupName">The group to get</param>
        /// <returns>Returns the GroupPrincipal Object</returns>
        public static GroupPrincipal GetGroup(string sGroupName)
        {
            try
            {
                PrincipalContext oPrincipalContext = ActiveDirectoryHelper.GetPrincipalContext();
                GroupPrincipal oGroupPrincipal = GroupPrincipal.FindByIdentity(oPrincipalContext, sGroupName);
                return oGroupPrincipal;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// Gets a list of the users Information
        /// </summary>
        /// <param name="sUserName">The user you want to get the Information</param>
        /// <returns>Returns an arraylist of userinformation</returns>
        public static UserProfileInfo GetProfile(string sUserName)
        {
            try
            {
                UserProfileInfo objinfo = new UserProfileInfo();
                PrincipalContext oPrincipalContext = ActiveDirectoryHelper.GetPrincipalContext();
                UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(oPrincipalContext, sUserName);
                if (oUserPrincipal != null)
                {
                    objinfo.FirstName = oUserPrincipal.GivenName;
                    objinfo.LastName = oUserPrincipal.Surname;
                    objinfo.Email = oUserPrincipal.EmailAddress;
                    objinfo.UserName = oUserPrincipal.SamAccountName;
                    objinfo.FullName = oUserPrincipal.DisplayName;
                    objinfo.ResPhone = oUserPrincipal.VoiceTelephoneNumber;
                    objinfo.AboutYou = oUserPrincipal.Description;

                }
                return objinfo;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        #endregion

        #region User Account Methods

        /// <summary>
        /// Creates a new user on Active Directory
        /// </summary>
        /// <param name="obj">The UserInfo object hold userinformation</param>   
        /// <returns>returns the UserPrincipal object</returns>
        public static UserPrincipal CreateNewUser(UserInfo obj)
        {
            try
            {
                if (!IsUserExisiting(obj.UserName))
                {
                    PrincipalContext oPrincipalContext = ActiveDirectoryHelper.GetPrincipalContext();

                    UserPrincipal oUserPrincipal = new UserPrincipal(oPrincipalContext, obj.UserName, obj.Password, true /*Enabled or not*/);

                    //User Log on Name  
                    if (oUserPrincipal != null)
                    {
                        oUserPrincipal.GivenName = obj.FirstName;
                        oUserPrincipal.Surname = obj.LastName;
                        oUserPrincipal.EmailAddress = obj.Email;
                        oUserPrincipal.Enabled = true;
                        oUserPrincipal.PasswordNeverExpires = false;
                        oUserPrincipal.SamAccountName = obj.UserName;
                        oUserPrincipal.DisplayName = obj.FirstName + " " + obj.LastName;
                        oUserPrincipal.UserPrincipalName = obj.UserName + "@" + ActiveDirectorySettings.ActiveDirectorySettingsConfig.Domain;
                        oUserPrincipal.Save();
                        string passwordchange;
                        SetUserPassword(obj.UserName, obj.Password, out passwordchange);
                    }
                    return oUserPrincipal;
                }
                else
                {
                    return GetUser(obj.UserName);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// Update user Details
        /// </summary>
        /// <param name="obj">The UserInfo object hold userinformation</param>           
        public static UserPrincipal UpdateUser(UserProfileInfo obj)
        {
            try
            {
                PrincipalContext oPrincipalContext = ActiveDirectoryHelper.GetPrincipalContext();
                UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(oPrincipalContext, obj.UserName);
                //User Log on Name         
                if (oUserPrincipal != null)
                {
                    oUserPrincipal.GivenName = obj.FirstName;
                    oUserPrincipal.Surname = obj.LastName;
                    oUserPrincipal.EmailAddress = obj.Email;
                    oUserPrincipal.Enabled = true;
                    oUserPrincipal.PasswordNeverExpires = false;
                    oUserPrincipal.SamAccountName = obj.UserName;
                    oUserPrincipal.DisplayName = obj.FirstName + " " + obj.LastName;
                    oUserPrincipal.VoiceTelephoneNumber = obj.ResPhone;
                    oUserPrincipal.Description = obj.AboutYou;
                    oUserPrincipal.UserPrincipalName = obj.UserName + "@" + ActiveDirectorySettings.ActiveDirectorySettingsConfig.Domain;
                    oUserPrincipal.Save();
                }
                return oUserPrincipal;
            }
            catch (Exception ex)
            {
                throw ex;
            }



        }

        /// <summary>
        /// Sets the user password
        /// </summary>
        /// <param name="sUserName">The username to set</param>
        /// <param name="sNewPassword">The new password to use</param>
        /// <param name="sMessage">Any output messages</param>
        public static void SetUserPassword(string sUserName, string sNewPassword, out string sMessage)
        {
            try
            {
                UserPrincipal oUserPrincipal = GetUser(sUserName);
                oUserPrincipal.SetPassword(sNewPassword);
                sMessage = "";
            }
            catch (Exception ex)
            {
                sMessage = ex.Message;
            }

        }

        /// <summary>
        /// Enables a disabled user account
        /// </summary>
        /// <param name="sUserName">The username to enable</param>
        public static void EnableUserAccount(string sUserName)
        {
            try
            {
                UserPrincipal oUserPrincipal = GetUser(sUserName);
                oUserPrincipal.Enabled = true;
                oUserPrincipal.Save();
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// Force disbaling of a user account
        /// </summary>
        /// <param name="sUserName">The username to disable</param>
        public static void DisableUserAccount(string sUserName)
        {
            try
            {
                UserPrincipal oUserPrincipal = GetUser(sUserName);
                oUserPrincipal.Enabled = false;
                oUserPrincipal.Save();
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// Force expire password of a user
        /// </summary>
        /// <param name="sUserName">The username to expire the password</param>
        public static void ExpireUserPassword(string sUserName)
        {
            try
            {
                UserPrincipal oUserPrincipal = GetUser(sUserName);
                oUserPrincipal.ExpirePasswordNow();
                oUserPrincipal.Save();
            }
            catch (Exception ex)
            {
                throw ex;
            }


        }

        /// <summary>
        /// Unlocks a locked user account
        /// </summary>
        /// <param name="sUserName">The username to unlock</param>
        public static void UnlockUserAccount(string sUserName)
        {
            try
            {
                UserPrincipal oUserPrincipal = GetUser(sUserName);
                oUserPrincipal.UnlockAccount();
                oUserPrincipal.Save();
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// Deletes a user in Active Directory
        /// </summary>
        /// <param name="sUserName">The username you want to delete</param>
        /// <returns>Returns true if successfully deleted</returns>
        public static bool DeleteUser(string sUserName)
        {
            try
            {
                UserPrincipal oUserPrincipal = GetUser(sUserName);
                oUserPrincipal.Delete();
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion

        #region Group Methods

        /// <summary>
        /// Creates a new group in Active Directory
        /// </summary>
        /// <param name="obj">The RoleInfo object holds all role information</param>
        /// <param name="status">The RoleCreationStatus object holds group existing informations</param>
        ///public GroupPrincipal CreateNewGroup(string sOU, string sGroupName, string sDescription, GroupScope oGroupScope, bool bSecurityGroup)      
        public static void CreateNewGroup(RoleInfo obj, out RoleCreationStatus status)
        {
            int ErrorCode = 0;
            //string sOU = "Builtin";
            try
            {
                if (!IsGroupExists(obj.RoleName))
                {
                    PrincipalContext oPrincipalContext = ActiveDirectoryHelper.GetPrincipalContext();
                    GroupPrincipal oGroupPrincipal = new GroupPrincipal(oPrincipalContext, obj.RoleName);
                    if (oGroupPrincipal != null)
                    {                     
                        oGroupPrincipal.Name = obj.RoleName;
                        oGroupPrincipal.Description = "All " + obj.RoleName;
                        oGroupPrincipal.GroupScope = GroupScope.Global;
                        oGroupPrincipal.IsSecurityGroup = true;
                        oGroupPrincipal.Save();
                    }
                }
                else
                {
                    ErrorCode = 1;
                }
                switch (ErrorCode)
                {
                    case 1:
                        status = RoleCreationStatus.DUPLICATE_ROLE;
                        break;
                    default:
                        status = RoleCreationStatus.SUCCESS;
                        break;
                }              

            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// Adds the user for a given group
        /// </summary>
        /// <param name="sUserName">The user you want to add to a group</param>
        /// <param name="sGroupName">The group you want the user to be added in</param>
        /// <returns>Returns true if successful</returns>
        public static bool AddUserToGroup(string sUserName, string sGroupName)
        {
            try
            {
                UserPrincipal oUserPrincipal = GetUser(sUserName);
                GroupPrincipal oGroupPrincipal = GetGroup(sGroupName);
                if (oUserPrincipal != null && oGroupPrincipal != null)
                {
                    if (!IsUserGroupMember(sUserName, sGroupName))
                    {
                        oGroupPrincipal.Members.Add(oUserPrincipal);
                        oGroupPrincipal.Save();
                    }
                }
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// Removes user from a given group
        /// </summary>
        /// <param name="sUserName">The user you want to remove from a group</param>
        /// <param name="sGroupName">The group you want the user to be removed from</param>
        /// <returns>Returns true if successful</returns>
        public static bool RemoveUserFromGroup(string sUserName, string sGroupName)
        {
            try
            {
                UserPrincipal oUserPrincipal = GetUser(sUserName);
                GroupPrincipal oGroupPrincipal = GetGroup(sGroupName);
                if (oUserPrincipal != null && oGroupPrincipal != null)
                {
                    if (IsUserGroupMember(sUserName, sGroupName))
                    {
                        oGroupPrincipal.Members.Remove(oUserPrincipal);
                        oGroupPrincipal.Save();
                    }
                }
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// Checks if user is a member of a given group
        /// </summary>
        /// <param name="sUserName">The user you want to validate</param>
        /// <param name="sGroupName">The group you want to check the membership of the user</param>
        /// <returns>Returns true if user is a group member</returns>
        public static bool IsUserGroupMember(string sUserName, string sGroupName)
        {
            try
            {
                UserPrincipal oUserPrincipal = GetUser(sUserName);
                GroupPrincipal oGroupPrincipal = GetGroup(sGroupName);
                if (oUserPrincipal != null && oGroupPrincipal != null)
                {
                    return oGroupPrincipal.Members.Contains(oUserPrincipal);
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// Gets a list of the users group memberships
        /// </summary>
        /// <param name="sUserName">The user you want to get the group memberships</param>
        /// <returns>Returns an arraylist of group memberships</returns>
        public static ArrayList GetUserGroups(string sUserName)
        {
            try
            {
                ArrayList myItems = new ArrayList();
                UserPrincipal oUserPrincipal = GetUser(sUserName);
                PrincipalSearchResult<Principal> oPrincipalSearchResult = oUserPrincipal.GetGroups();
                foreach (Principal oResult in oPrincipalSearchResult)
                {
                    myItems.Add(oResult.Name);
                }
                return myItems;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// Gets a list of the users authorization groups
        /// </summary>
        /// <param name="sUserName">The user you want to get authorization groups</param>
        /// <returns>Returns an arraylist of group authorization memberships</returns>
        public static ArrayList GetUserAuthorizationGroups(string sUserName)
        {
            try
            {
                ArrayList myItems = new ArrayList();
                UserPrincipal oUserPrincipal = GetUser(sUserName);
                PrincipalSearchResult<Principal> oPrincipalSearchResult = oUserPrincipal.GetAuthorizationGroups();
                foreach (Principal oResult in oPrincipalSearchResult)
                {
                    myItems.Add(oResult.Name);
                }
                return myItems;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        /// <summary>
        /// Gets a list of the users authorization groups
        /// </summary>
        /// <param name="sGroupName">The group you want to get existing information</param>
        /// <returns>Returns true or false according group existance</returns>
        public static bool IsGroupExists(string sGroupName)
        {
            try
            {
                bool exists = false;

                PrincipalContext oPrincipal = ActiveDirectoryHelper.GetPrincipalContext();
                GroupPrincipal gPrincipal = GroupPrincipal.FindByIdentity(oPrincipal, IdentityType.SamAccountName, sGroupName);

                if (gPrincipal != null)
                {
                    exists = true;
                }
                return exists;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        #endregion


    }
}


V.            ActiveDirectoryRoleProvider.cs

using System;
using System.Collections.Generic;
using System.Web.Security;
using System.Web.Configuration;
using System.Globalization;
using System.DirectoryServices;
using System.Collections.Specialized;
using System.DirectoryServices.AccountManagement;
using System.Collections;
using Application.Security;


namespace Application.Security
{
    public class ActiveDirectoryRoleProvider : RoleProvider
    {      

        public override bool IsUserInRole(string username, string roleName)
        {
            string[] roles = GetRolesForUser(username);

            foreach (string role in roles)
            {
                if (role.Equals(roleName, StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
            }

            return false;
        }

        public override string[] GetRolesForUser(string username)
        {
            try
            {
                var myItems = new List<string>();
                UserPrincipal oUserPrincipal = ADMembeshipController.GetUser(username);
                PrincipalSearchResult<Principal> oPrincipalSearchResult = oUserPrincipal.GetGroups();
                foreach (Principal oResult in oPrincipalSearchResult)
                {
                    myItems.Add(oResult.Name);
                }
                return myItems.ToArray();
            }
            catch (Exception ex)
            {
                throw ex;
            }
           
        }             

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            try
            {
                var AllGroups = new List<string>();
                PrincipalContext ctx = ActiveDirectoryHelper.GetPrincipalContext();
                GroupPrincipal qbeUser = new GroupPrincipal(ctx);
                Principal userOrGroup = qbeUser as Principal;
                userOrGroup.Name = "*";
                PrincipalSearcher searcher = new PrincipalSearcher(userOrGroup);              

                // enumerate the results - you need to check what kind of principal you get back
                foreach (Principal found in searcher.FindAll())
                {
                    // is it a UserPrincipal - do what you need to do with that...
                    if (found is UserPrincipal)
                    {
                        //  ......

                    }
                    else if (found is GroupPrincipal)
                    {
                        AllGroups.Add(found.Name);

                    }
                }

                return AllGroups.ToArray();
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }             

        public override string[] GetUsersInRole(string roleName)
        {
            try
            {
                List<string> users = new List<string>();

                PrincipalContext oPrincipal = ActiveDirectoryHelper.GetPrincipalContext();
                GroupPrincipal gPrincipal = GroupPrincipal.FindByIdentity(oPrincipal, IdentityType.SamAccountName, roleName);

                if (gPrincipal != null)
                {
                    foreach (Principal p in gPrincipal.GetMembers(false))
                    {
                        users.Add(p.DisplayName);
                    }
                }

                return users.ToArray();
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }      

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            try
            {
                bool exists = false;

                PrincipalContext oPrincipal = ActiveDirectoryHelper.GetPrincipalContext();
                GroupPrincipal gPrincipal = GroupPrincipal.FindByIdentity(oPrincipal, IdentityType.SamAccountName, roleName);

                if (gPrincipal != null)
                {
                    exists = true;
                }
               return exists;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

    }
}


VI.           ADMembeshipController.cs

using System.DirectoryServices.AccountManagement;
using System.Collections;
using DemoSite.UserProfile;
using System.Collections.Generic;
using Application.Security.Helpers;

namespace Application.Security
{
 public static  class ADMembeshipController
    {

        #region Validate Methods
      
        public static bool ValidateCredentials(string sUserName, string sPassword)
        {
            return ADMembershipDataProvider.ValidateCredentials(sUserName,sPassword);
          
        }      
        public static bool IsUserExpired(string sUserName)
        {
            return ADMembershipDataProvider.IsUserExpired(sUserName);          
        }
           
        public static bool IsUserExisiting(string sUserName)
        {
         return ADMembershipDataProvider.IsUserExisiting(sUserName);
          
        }     
        public static bool IsUserEmailExists(string email)
        {
            return ADMembershipDataProvider.IsUserEmailExists(email);
          
        }
     
        public static bool IsAccountLocked(string sUserName)
        {
            return ADMembershipDataProvider.IsAccountLocked(sUserName);
          
        }
        #endregion

        #region Search Methods      
        public static UserPrincipal GetUser(string sUserName)
        {
            return ADMembershipDataProvider.GetUser(sUserName);
         
        }
        public static DemoSiteUserCollection SearchUsers(string roleName, string username)
        {
            return ADMembershipDataProvider.SearchUsers(roleName, username);
        }
        public static List<string> GetAllUsers(string sGroupName)
        {
            return ADMembershipDataProvider.GetAllUsers(sGroupName);
        }
        public static List<RoleInfo> GetAllGroups()
        {
            return ADMembershipDataProvider.GetAllGroups();
        }
      
        public static GroupPrincipal GetGroup(string sGroupName)
        {
            return ADMembershipDataProvider.GetGroup(sGroupName);
        }
        public static UserProfileInfo GetProfile(string sUserName)
        {
            UserProfileInfo objinfo = new UserProfileInfo();
            objinfo = ADMembershipDataProvider.GetProfile(sUserName);
            return objinfo;
        }

        #endregion

        #region User Account Methods
     
        public static UserPrincipal CreateNewUser(UserInfo obj)
        {
            return ADMembershipDataProvider.CreateNewUser(obj);  
        }
        public static UserPrincipal UpdateUser(UserProfileInfo obj)
        {
            return ADMembershipDataProvider.UpdateUser(obj);
        }
          
        public static void SetUserPassword(string sUserName, string sNewPassword, out string sMessage)
        {
           ADMembershipDataProvider.SetUserPassword(sUserName,sNewPassword, out sMessage);  

        }

        public static void EnableUserAccount(string sUserName)
        {
            ADMembershipDataProvider.EnableUserAccount(sUserName);  
        }
      
        public static void DisableUserAccount(string sUserName)
        {
            ADMembershipDataProvider.DisableUserAccount(sUserName);  
        }
      
        public static void ExpireUserPassword(string sUserName)
        {
            ADMembershipDataProvider.ExpireUserPassword(sUserName);  

        }
      
        public static void UnlockUserAccount(string sUserName)
        {
            ADMembershipDataProvider.UnlockUserAccount(sUserName);  
        }

        public static bool DeleteUser(string sUserName)
        {
            return ADMembershipDataProvider.DeleteUser(sUserName);  
        }

        #endregion

        #region Group Methods    
  
        public static void CreateNewGroup(RoleInfo obj, out RoleCreationStatus status)
        {
            ADMembershipDataProvider.CreateNewGroup(obj, out status);  
        }

        public static bool AddUserToGroup(string sUserName, string sGroupName)
        {
            return ADMembershipDataProvider.AddUserToGroup(sUserName, sGroupName); 
        }

        public static bool RemoveUserFromGroup(string sUserName, string sGroupName)
        {
            return ADMembershipDataProvider.RemoveUserFromGroup(sUserName, sGroupName); 
        }
      
        public static bool IsUserGroupMember(string sUserName, string sGroupName)
        {
            return ADMembershipDataProvider.IsUserGroupMember(sUserName, sGroupName); 
        }

        public static ArrayList GetUserGroups(string sUserName)
        {
            return ADMembershipDataProvider.GetUserGroups(sUserName); 
        }

        public static ArrayList GetUserAuthorizationGroups(string sUserName)
        {
            return ADMembershipDataProvider.GetUserAuthorizationGroups(sUserName); 
        }
        public static bool IsGroupExists(string sGroupName)
        {
            return ADMembershipDataProvider.IsGroupExists(sGroupName); 
        }

        #endregion

        #region Helper Methods

        public static PrincipalContext GetPrincipalContext()
        {
            return ActiveDirectoryHelper.GetPrincipalContext();
        }

        public static PrincipalContext GetPrincipalContext(string sOU)
        {
            return ActiveDirectoryHelper.GetPrincipalContext(sOU);
        }

        #endregion


    }
}



VII.         ActiveDirectoryRoleController.cs

using System;
using Application.Security.Entities;

namespace Application.Security
{
 public  class ActiveDirectoryRoleController:ActiveDirectoryRoleProvider
    {
    
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            ActiveDirectoryRoleProvider rp = new ActiveDirectoryRoleProvider();
            return rp.GetAllRoles();
        }

        public override string[] GetRolesForUser(string username)
        {
            ActiveDirectoryRoleProvider rp = new ActiveDirectoryRoleProvider();
            return (rp.GetRolesForUser(username));
           // throw new NotImplementedException();
        }

        public override string[] GetUsersInRole(string roleName)
        {
            ActiveDirectoryRoleProvider rp = new ActiveDirectoryRoleProvider();
            return (rp.GetUsersInRole(roleName));
        }
        
        public override bool IsUserInRole(string username, string roleName)
        {
            throw new NotImplementedException();
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }

    }
}


    3.     Login.aspx.cs (Asp.net Page)

if (!(string.IsNullOrEmpty(UserName.Text) && string.IsNullOrEmpty(Password.Text)))
            {             
                if (true == ADMembeshipController.IsUserExisiting(UserName.Text))
                {                  
                    if (true == ADMembeshipController.ValidateCredentials(UserName.Text, Password.Text))
                    {
                         //SucessFullLogin(user);
                    }
                 }
            }

Note:
Doing this you can face connection permission exceptions like
Principal Server Down Exception, The server could not be contacted.

For this configure your DNS in remote and resolve the IP Address of your computer