2

I've read several posts about this (such as this one and this one describing a bug in the WebConfig) but none of them describing a full explanation on how to implement the LDAP authentication on MVC3. I've been doing it with Web Forms without any issues but in MVC my main issue at the moment is that the application never redirects to the my Authentication/Login controller/action.

Here's my WebConfig:

<connectionStrings>
    <add name="ADConnectionString" connectionString="LDAP://blablabla.net"/>
</connectionStrings>

<authentication mode="Forms">
  <forms loginUrl="~/Authentication/Login" timeout="100000" name="adAuthCookie" />
</authentication>

<membership defaultProvider="blablablaMembershipProvider">
  <providers>
    <add name="blablablaMembershipProvider"
         type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
         connectionStringName="ADConnectionString"
         connectionProtection="Secure"
         attributeMapUsername="sAMAccountName"
         enableSearchMethods="false" />
  </providers>
</membership>

I've also tried to use a simple Logon.aspx page that I've put in my Views folder and use routes.MapPageRoute but that didn't work either. routes.MapPageRoute("ASPX", "Views", "~/Logon.aspx");

Many other sites also describe how to implement this but don't go further than the WebConfig configuration.

I would really appreciate any help on this!

Thanks

Community
  • 1
  • 1
LanFeusT
  • 2,392
  • 5
  • 38
  • 53
  • Did you apply the [Authorize] attribute on controllers or actions which require authorization? – eulerfx Feb 28 '11 at 19:57
  • Yes I have. However I started the MVC project as an empty one and never added the LogonDisplay part. When I did I saw that I was logged in the entire time, somehow my app logged me in automatically which was why it was never redirecting me to the login page. The ASPX part still doesn't work, but at least now I can work on the authentication part and not the redirect. – LanFeusT Feb 28 '11 at 20:13

1 Answers1

1

So this wasn't very smart.

My issue was caused by the fact that I was using an empty MVC project. Because of that I never saw that I was not already logged in which obviously did not redirect me to the login page. When I adde a @if(Request.IsAuthenticated) the tool showed me logged in.

The moment I started a new non-empty project I got access to the default Account/LogOn controller/action which works perfectly now.

Following some of the sites I linked previously to add the LDAP connection string made the trick.

LanFeusT
  • 2,392
  • 5
  • 38
  • 53