且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET MVC - 验证对Active Directory用户,但需要用户名和密码将被输入

更新时间:2021-12-24 00:18:54

您可以使用与窗体身份验证标准的Internet应用程序模板并插入 ActiveDirectoryMembershipProvider 的web.config

You can use the standard Internet application template with forms authentication and insert an ActiveDirectoryMembershipProvider into the web.config:

<connectionStrings>
    <add name="ADConnectionString" connectionString="YOUR_AD_CONN_STRING" />
</connectionStrings>

<system.web>
    <authentication mode="Forms">
        <forms name=".ADAuthCookie" loginUrl="~/Account/LogOn" timeout="15" slidingExpiration="false" protection="All" />
    </authentication>
    <membership defaultProvider="MY_ADMembershipProvider">
        <providers>
            <clear />
            <add name="MY_ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" />
        </providers>
    </membership>
</system.web>

在这种方式,您获得互联网应用程序模板登录表单,并验证对广告给你。

In this way you get the Internet application template login form, and it validates against AD for you.

然后,它只是一个部分的AccountController 清理事项移除重置密码/更改密码/注册功能,只留下登录。

Then it's just a matter of some AccountController cleanup to remove reset password/change password/register functionality leaving just Login.