在MVC4控制器上的LDAP实现
本文关键字:LDAP 实现 MVC4 控制器 | 更新日期: 2023-09-27 18:12:00
我是新的ASP.net MVC,我有这个控制器,使用Windows身份验证(xxxxDMZ'username
,密码):
[Authorize]
public class ExController : Controller
{
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
base.Initialize(requestContext);
ViewBag.user = User.Identity.Name;
}
public ActionResult Index()
{
return View();
}
}
现在我需要使用一个不同的域(xxxx'username
,密码)来访问这个控制器。
web . config:
<system.web>
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<authentication mode="Windows" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="GridMvc" />
</namespaces>
</pages>
<membership>
<providers>
<clear />
</providers>
</membership>
</system.web>
当前IIS 7.5配置:启用Windows身份验证(启用提供商:协商,NTLM),启用匿名身份验证
指出:
- 网站托管在服务器上,可以使用RDC访问
xxxDMZ'username
。 -
xxxDMZ'username
和xxx'username
完全不同。 - 用户登录windows时,使用
xxx'username
这个账号。 - 我希望用户不使用凭据浏览网站,我只需要他们在尝试访问上述控制器时使用凭据(xxxx'username, password)。
- 我的问题是不是所有(xxxx'用户名,密码)用户都有(xxxxDMZ'用户名,密码)帐户。
我认为你需要为你的身份验证配置一个ActiveDirectoryMembershipProvider
网络。配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<authentication mode="Forms">
<forms name=".ADAuthCookie" loginUrl="~/Account/Login" timeout="45" slidingExpiration="false" protection="All" />
</authentication>
<membership defaultProvider="ADMembershipProvider">
<providers>
<clear />
<add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" />
</providers>
</membership>
</system.web>
<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://primary.mydomain.local:389/DC=MyDomain,DC=Local" />
</connectionStrings>
</configuration>
请参考http://www.schiffhauer.com/mvc-5-and-active-directory-authentication/