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
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.