I Created custom login page .

I use this code for login

if (Membership.ValidateUser(Username.Text, Password.Text))


    SecurityToken tk = SPSecurityContext.SecurityTokenForFormsAuthentication(

        new Uri(SPContext.Current.Web.Url), "ADProvider", null,

        Username.Text, Password.Text);

    if (tk != null)


        SPFederationAuthenticationModule fam = SPFederationAuthenticationModule.Current;


        //look for the Source query string parameter and use that as the redirection

        string src = page.Request.QueryString["Source"];

        if (!string.IsNullOrEmpty(src))


            Response.Redirect(src, false);




            Response.Redirect("/", false);



I add connectionstring and membersgip for webconfig


<add name="AdConn" connectionString="LDAP://domain.local/DC=domain,DC=local" />


<membership defaultProvider="i">





      type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 



      attributeMapUsername="sAMAccountName" />




but when i login , i get

Error: Access Denied

1 Answer 1


Open Central Administration and go to Application Management.now hit User Policy ribbon option in the Web Applications Management page having selected your web application. Hit Add Users in the Policy for Web Application dialog. Hit Next in Add Users dialog. Use the Browse button in the Choose Users people picker control. Notice the Select People and Groups dialog that comes up is changed. Noticeable difference is that there are sections like Active Directory, All Users, Forms Auth & Organizations. Type in an active directory user alias and search. There should be 2 results for the same user. Select the user from Forms Auth result.

enter image description here

Now, your Policy for Web Application dialog should look like Image

enter image description here

I use this link. It is useful for me.

  • 1
    good that you solved it. Please elaborate a bit in the answer on how this solved your issue. Those external links tend to be shorter lived than our site, so please insert a few lines and then link :-) thx May 16, 2012 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.