ASP.NET MVC - 根据 Active Directory 对用户进行身份验证,但需要输入用户名和密码 [英] ASP.NET MVC - Authenticate users against Active Directory, but require username and password to be inputted

本文介绍了ASP.NET MVC - 根据 Active Directory 对用户进行身份验证,但需要输入用户名和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 MVC3 应用程序,该应用程序将要求用户根据 AD 进行身份验证.我知道 MVC3 中有一个选项可以创建一个 Intranet 应用程序,该应用程序可以根据 AD 自动对用户进行身份验证,但它使用 Windows 身份验证并自动登录.此应用程序可以在开放"工作站上访问,用户需要在其中输入他们的域用户名和密码.任何示例或在线教程都会很棒.一个示例项目会很特别.

I'm developing a MVC3 application that will require a user to be authenticated against an AD. I know that there is the option in MVC3 to create an Intranet Application that automatically authenticates a user against an AD, but it uses Windows Authentication and automatically logs them on. This application may be accessed on 'Open' workstations where the user will need to enter their Domain Username and Password. Any examples or online tutorial would be great. An example project would be exceptional.

推荐答案

您可以使用带有表单身份验证的标准 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="LDAP://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>

通过这种方式,您可以获得 Internet 应用程序模板登录表单,它会为您验证 AD.

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.

这篇关于ASP.NET MVC - 根据 Active Directory 对用户进行身份验证,但需要输入用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆