简体   繁体   English

ASP.NET MVC Windows身份验证在表单身份验证之上

[英]ASP.NET MVC Windows authentication on top of forms authentication

I have developed a web app in ASP.NET MVC which we are using internally. 我在ASP.NET MVC中开发了一个我们在内部使用的Web应用程序。 Now we want to make it available through our server on the internet -- to make life easier when we're doing jobs on site. 现在我们希望通过互联网上的服务器提供它 - 当我们在现场做工作时,让生活更轻松。

Ideally I'd like to just stick Windows authentication infront of it, so that anyone with a domain account can log in. 理想情况下,我只想坚持使用Windows身份验证,以便拥有域帐户的任何人都可以登录。

The problem is that I'm already using forms authentication in the app. 问题是我已经在应用程序中使用表单身份验证。

We don't have any password restrictions for the app, you simply select the user you wish to log in as and then submit the form. 我们对该应用没有任何密码限制,您只需选择要登录的用户,然后提交表单即可。 On the server side it just does this - 在服务器端它只是这样做 -

    FormsAuthentication.SetAuthCookie(viewModel.Username, true);

This makes the user's name available throughout all controllers and views using the User object (user.identity.name). 这使用户对象(user.identity.name)在所有控制器和视图中提供用户名。

However... when I enable Windows authentication in IIS, the web app starts thinking that user.identity.name is "ourdomain\\domainuser". 但是......当我在IIS中启用Windows身份验证时,Web应用程序开始认为user.identity.name是“ourdomain \\ domainuser”。

What I'd like is to use forms authentication in conjunction with windows authentication, but not have them integrate in any way. 我想要的是将表单身份验证与Windows身份验证结合使用,但不要以任何方式集成它们。

Is there a simple way to achieve this? 有没有一种简单的方法来实现这一目标?

The ASP.NET team doesn't officially support using mixed-mode authentication in an application. ASP.NET团队不正式支持在应用程序中使用混合模式身份验证。 If you search the web, you'll find blog posts on how to do this, but please note that they're discouraged by the ASP.NET team. 如果您在网上搜索,您会发现有关如何执行此操作的博客文章,但请注意,ASP.NET团队不鼓励他们。 The reason this is discouraged is that it is very difficult to reason about from a correctness point of view, and there are trivial attacks against such a setup that can allow malicious clients to masquerade as an authenticated user. 不鼓励这样做的原因是,从正确的角度来看很难进行推理,并且存在针对这样的设置的轻微攻击,其可以允许恶意客户端伪装成经过身份验证的用户。

You cannot use forms authentication and Windows authentication at the same time in IIS 7 and higher under Integrated Mode. 在集成模式下,您无法在IIS 7及更高版本中同时使用表单身份验证和Windows身份验证。 Therefore, I would highly discourage that approach. 因此,我强烈反对这种做法。 You can however, use the built-in ActiveDirectoryMembershipProvider Class to authenticate Windows user accounts through a form and tie your login to that. 但是,您可以使用内置的ActiveDirectoryMembershipProvider类通过表单对Windows用户帐户进行身份验证,并将您的登录信息绑定到该用户帐户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM