Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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;

        fam.SetPrincipalAndWriteSessionToken(tk);



        //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);

        }

        else

        {

            Response.Redirect("/", false);

        }

    }

I add connectionstring and membersgip for webconfig

  <connectionStrings>

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

...

<membership defaultProvider="i">

  <providers>

    ...

    <add 

      name="AdProvider" 

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

      connectionStringName="AdConn" 

      enableSearchMethods="true" 

      attributeMapUsername="sAMAccountName" />

  </providers>

</membership>

...

but when i login , i get

Error: Access Denied

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
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 –  Anders Rask May 16 '12 at 8:41
    
Anders Rask♦: ok, Thanks :) –  ar.gorgin May 16 '12 at 9:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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