我是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身份验证(已启用提供程序:Negotiate,NTLM),已启用匿名身份验证
备注:
xxxDMZ\username
。xxxDMZ\username
和xxx\username
完全不同。xxx\username
。答案 0 :(得分:0)
我认为您需要为您的身份验证配置ActiveDirectoryMembershipProvider。
web.config:
<?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/