Authentication ASP.NET MVC3 IIS6允许域用户访问站点,但允许其他用户连接到数据库

Authentication ASP.NET MVC3 IIS6允许域用户访问站点,但允许其他用户连接到数据库,authentication,.net-4.0,iis-6,authorization,asp.net-mvc-3,Authentication,.net 4.0,Iis 6,Authorization,Asp.net Mvc 3,MVC3(可能与1和2相同)、Server2003、IIS6、.NET4、SQLServer2005 我有一个简单的管理员应用程序,只有两三个人会登录,所以我不想麻烦表单验证、单独的用户名/密码等等。我只想让用户使用他们现有的广告用户/pw登录。但是我想通过一个专用帐户连接到SQL Server,该帐户已经对所选数据库具有适当的权限 我在经典asp中使用以下场景完成了此操作 IIS: Enable anonymous Access: checked. Username/pw dedicated

MVC3(可能与1和2相同)、Server2003、IIS6、.NET4、SQLServer2005

我有一个简单的管理员应用程序,只有两三个人会登录,所以我不想麻烦表单验证、单独的用户名/密码等等。我只想让用户使用他们现有的广告用户/pw登录。但是我想通过一个专用帐户连接到SQL Server,该帐户已经对所选数据库具有适当的权限

我在经典asp中使用以下场景完成了此操作

IIS: Enable anonymous Access: checked.  Username/pw dedicated account for the SQL Server DB
Integrated Windows authentication: unchecked
Digest authentication: unchecked
Basic authentication: unchecked
.NET Passport authentication: unchecked
经典的asp应用程序接受发布的HTML表单,然后通过LDAP进行身份验证

' Establish connection
Set objConnection = Server.CreateObject("ADODB.Connection")

' Connection properties
objConnection.Provider = "ADsDSOOBJECT"
objConnection.Properties("User ID") = strUsername
objConnection.Properties("Password") = strPassword
objConnection.Properties("Encrypt Password") = True

' Open connection
objConnection.open "DS Query", strUsername, strPassword  ' user supplied user/pw

' Query Active Directory
strQuery = "SELECT cn FROM 'LDAP://" & strDomain & "' WHERE objectClass='*' "

Set objCommand = server.CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = strQuery

' Get recordset
Set objRS = objCommand.Execute

' If no record of user found
If objRS.BOF Or objRS.EOF Then

    ' User does not exist
    AuthenticateUser = False

Else

    ' User is authentic
    AuthenticateUser = True

End If
我希望在.NET中有同样的行为,但没有HTML表单。当用户访问具有[授权]属性的控制器时,似乎有可能:

[Authorize(Users = @"domain\user1, domain\user2, domain\user3")]
提示他们输入广告用户/pw(或不使用IE,取决于区域和自动登录选项),然后进行身份验证,但使用IIS中的专用用户连接到DB。我如何做到这一点

我一直认为模拟是一种方式,因此这在我的web.config中:

  <system.web>
    <identity impersonate="true"/>
    <authentication mode="Windows" />
失败了。 用户“域\用户3”登录失败

很明显,模仿在这里不起作用

因此,这必须是一个非常典型的示例,说明如何在普通windows网络上通过防火墙进行身份验证。最好的方法是什么?我曾经考虑过使用类似代码的自定义AuthorizeAttribute,它似乎更接近于经典asp应用程序中的工作方式,但出于某种原因,我认为我只需通过设置和配置就可以实现所有功能

EDIT1:

在阅读了Barry Dorrans昨晚开始的ASP.NET安全性之后,我似乎可以更改应用程序池的用户,并让该用户访问SQL Server数据库。是这样吗?或者是网站设置中的Anon用户点击了DB

已尝试更改应用程序池用户,但该帐户不是IIS\u WPG组的一部分。这是必须的,对吗

EDIT2: 选中基本身份验证后,如果未与指定用户进行检查,则会得到以下结果:

User.Identity.Name: DOMAIN\jcurran
User.Identity.IsAuthenticated: True
User.Identity.AuthenticationType: Basic


WindowsIdentity.GetCurrent().AuthenticationType: Kerberos
WindowsIdentity.GetCurrent().Name: DOMAIN\jcurran
WindowsIdentity.GetCurrent().IsAuthenticated: True
WindowsIdentity.GetCurrent().IsAnonymous: False
WindowsIdentity.GetCurrent().IsGuest: False
WindowsIdentity.GetCurrent().IsSystem: False
WindowsIdentity.GetCurrent().ImpersonationLevel.ToString(): Impersonation


Thread.CurrentPrincipal.Identity.Name: DOMAIN\jcurran 
未选中基本身份验证,未选中指定用户,我得到一个空白页。用提琴手检查产量:

HTTP/1.1 401 Unauthorized
Date: Thu, 06 Jan 2011 18:02:42 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
X-AspNetMvc-Version: 3.0
Cache-Control: private
Content-Length: 0

假设您希望使用Windows Auth访问SQL server,那么这是一种方法

在web.config中,您需要设置
impersonate=“false”
,否则ASP.NET将尝试使用客户端的凭据而不是应用程序池的凭据来连接到数据库(即,看起来模拟正在执行您要求它执行的操作)


在IIS中,您必须启用集成的Windows Auth,如果需要,您可以禁用匿名访问。

假设您希望使用Windows Auth访问SQL server,那么这就是解决方法

在web.config中,您需要设置
impersonate=“false”
,否则ASP.NET将尝试使用客户端的凭据而不是应用程序池的凭据来连接到数据库(即,看起来模拟正在执行您要求它执行的操作)


在IIS中,您必须启用集成Windows身份验证,如果需要,您可以禁用匿名访问。

非常感谢。因此,我学到了一些关于模拟的知识,它的作用与我想象的相反:)我将帐户添加到IIS_WPG组,更改了应用程序池用户,删除了impersonate=“true”,一切似乎都正常。也谢谢你帮助这个小家伙。我知道你已经习惯了更棘手的问题;-)非常感谢。因此,我学到了一些关于模拟的知识,它的作用与我想象的相反:)我将帐户添加到IIS_WPG组,更改了应用程序池用户,删除了impersonate=“true”,一切似乎都正常。也谢谢你帮助这个小家伙。我知道你已经习惯了更棘手的问题;-)
User.Identity.Name: DOMAIN\jcurran
User.Identity.IsAuthenticated: True
User.Identity.AuthenticationType: Basic


WindowsIdentity.GetCurrent().AuthenticationType: Kerberos
WindowsIdentity.GetCurrent().Name: DOMAIN\jcurran
WindowsIdentity.GetCurrent().IsAuthenticated: True
WindowsIdentity.GetCurrent().IsAnonymous: False
WindowsIdentity.GetCurrent().IsGuest: False
WindowsIdentity.GetCurrent().IsSystem: False
WindowsIdentity.GetCurrent().ImpersonationLevel.ToString(): Impersonation


Thread.CurrentPrincipal.Identity.Name: DOMAIN\jcurran 
HTTP/1.1 401 Unauthorized
Date: Thu, 06 Jan 2011 18:02:42 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
X-AspNetMvc-Version: 3.0
Cache-Control: private
Content-Length: 0