简体   繁体   English

在asp.net中获取Windows /域凭据,同时允许在IIS中进行匿名访问

[英]Getting windows/domain credentials in asp.net while allowing anonymous access in IIS

I have an asp.NET webapplication running in our datacenter in which we want the customer to logon with single sign-on. 我在我们的数据中心运行了一个asp.NET webapplication,我们希望客户通过单点登录进行登录。 This would be very easy if we could use the IIS integrated security. 如果我们可以使用IIS集成安全性,这将非常容易。 However we can't do this. 但是我们不能这样做。 We don't have a trust to the domain controller of the customer. 我们对客户的域控制器没有信任。 ANd we want to website to be available to the general internet. 我们希望网站可用于一般互联网。 Only when people are connecting from within the clients network they should automatically login. 只有当人们从客户网络中连接时,他们才会自动登录。

What we have is a list of domain accounts and a way to query the DC via LDAP in asp.net code. 我们拥有的是域帐户列表以及在asp.net代码中通过LDAP查询DC的方法。 When anonymous access is allowed in IIS, IIS never challenges the browser for credentials. 在IIS中允许匿名访问时,IIS永远不会向浏览器挑战凭据。 And thus our application never gets the users credentials. 因此我们的应用程序永远不会获得用户凭据。

Is there a way to force the browser into sending the credentials (and thus be able to use single sign-on) with IIS accepting anonymous request. 有没有办法强制浏览器发送凭据(因此能够使用单点登录)与IIS接受匿名请求。

Update: 更新:

I tried sending 401: unauthorized, www-authenticate: NTLM headers by myself. 我尝试自己发送401:未经授权,www-authenticate:NTLM标头。 What happens next (as Fiddler tells me) is that IIS takes complete control and handles the complete chain of request. 接下来发生的事情(正如Fiddler告诉我的那样)是IIS完全控制并处理完整的请求链。 As I understand from various sources is that IIS takes the username, sends a challenge back to the browser. 据我从各种来源了解,IIS采用用户名,将挑战发送回浏览器。 The browser returns with encrypted reponse and IIS connects to the domain controller to authenticate the user with this response. 浏览器返回加密响应,IIS连接到域控制器以使用此响应对用户进行身份验证。

However in my scenario IIS is in a different windows domain than the clients and have no way to authenticate the users. 但是在我的方案中,IIS与客户端位于不同的Windows域中,无法对用户进行身份验证。 For that reason building a seperate site with windows authenticaion enabaled isn't going to work either. 因此,建立一个带有Windows身份验证功能的独立站点也无法正常工作。

For now I have to options left which I'm researching: 现在我需要选择我正在研究的选项:

  1. Creating a domain trust between our hosting domain and the clients domain (our IT department isn'tto happy with this) 在我们的托管域和客户域之间创建域信任(我们的IT部门对此不满意)
  2. Using a NTML proxy to forward the IIS authentication requests to the clients domain controller (we have a VPN connection available to connect via LDAP) 使用NTML代理将IIS身份验证请求转发到客户端域控制器(我们有可通过LDAP连接的VPN连接)

What you're asking for is called mixed mode authentication. 您要求的是混合模式身份验证。 I've recently used a two entry-point mechanism from Paul Glavich and it works perfectly. 我最近使用了Paul Glavich两个入口点机制 ,它完美无缺。 I guess it's the most elegant solution for this problem. 我想这是解决这个问题最优雅的解决方案。

Not sure that you'll easily get this to work. 不确定你是否能轻松实现这一目标。 Unlike basic where the 401 challenge happens in-band of the user request - such that the creds appear in the headers, NTLM handshakes are done on a separate port - then forced onto the thread context by unmanaged code. 与401挑战发生在用户请求的带内基本不同 - 这样,信用证出现在标题中,NTLM握手在一个单独的端口上完成 - 然后由非托管代码强制进入线程上下文。

You tried pulling apart the ASP.NET NTLM module in VS2008 (or reflector) to see what it does to extract the creds? 你试图拆开VS2008(或反射器)中的ASP.NET NTLM模块,看看它是如何提取信用卡的?

Not really an answer - sorry... 不是真的答案 - 对不起......

This solution is about forms authentication, but it details the 401 issue. 此解决方案是关于表单身份验证,但它详细说明了401问题。

The solution was simply to attach a handler to the Application's EndRequest event by putting the following in Global.asax: 解决方案只是通过将以下内容放在Global.asax中来将处理程序附加到Application的EndRequest事件:

protected void Application_EndRequest(object sender, EventArgs e) {
    if (Context.Items["Send401"] != null)
    {
         Response.StatusCode = 401;
         Response.StatusDescription = "Unauthorized";
    } }

Then, in order to trigger this code, all you have to do is put a 然后,为了触发此代码,您所要做的就是放一个

Context.Items["Send401"] = true;

Edit: 编辑:
I've used this method with Anonymous and Integrated turned on to get the user's domain credentials. 我已经使用此方法打开Anonymous和Integrated来获取用户的域凭据。 I'm not sure if it'll work in your situation, but I thought I was worth a shot. 我不确定它是否适用于你的情况,但我认为我值得一试。

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

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