如何解决双跳 IIS 到 SQL Server 身份验证在本地工作,不能远程工作
关于双跳身份验证浏览器的问题-> IIS(ASP.NET WebForms 应用程序)-> SQL Server。
我有一个带有 Web.config 的 WebForms 网站,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="devExpress">
...some DevExpress settings here...
</sectionGroup>
</configSections>
<connectionStrings>
<add name="ConnStringName" connectionString="Data Source=SERVER_NAME;Initial Catalog=DB_NAME;Trusted_Connection=Yes;Integrated Security=SSPI;Persist Security Info=False;Connect Timeout=0" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<identity impersonate="true" />
...
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
...
<httpRuntime maxRequestLength="4096" requestValidationMode="4.0" executionTimeout="110" targetFramework="4.5.2" />
<pages validateRequest="true" clientIDMode="Predictable">
...
</pages>
<sessionState mode="InProc" timeout="60"></sessionState>
</system.web>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="Default.aspx" />
</files>
</defaultDocument>
...
<validation validateIntegratedModeConfiguration="false" />
...
</configuration>
我需要它这样工作:当域中的任何用户在浏览器中打开站点时,ASP.NET Web 窗体应用程序在他的 Windows 凭据下运行。然后,必须使用相同的凭据来验证 ASP.NET 应用程序使用 SqlConnection 类进行的数据库调用。
为清楚起见:SQL Server 配置为使用 Windows 身份验证。必须有权访问应用程序和数据库的用户包含在特定的 AD 组中。该组列在 DB 的 Security - Logins 列表中,具有 data_reader、data_writer 权限(并且它们还可以执行存储过程)。
最有趣的是它真正是如何工作的:
#1.当我在 IIS 所在的服务器上打开浏览器时,输入 http://localhost:port/ - 它按预期工作。
#2.当我在我的 PC 上打开浏览器时,输入 http://server-name:port/ - 它捕获 SqlConnection 打开错误:
System.Data.SqlClient.SqlException
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
在这两种情况下,Context.User.Identity.Name 和 WindowsIdentity.GetCurrent().Name 都是正确的。
为什么这两种情况会给出不同的结果?如何让 #2 像 #1 一样工作?
解决方法
由于这是双跳身份验证方案,因此您必须启用 Kerberos Constrained Delegation。参见例如Setting up Kerberos Authentication for a Website in IIS。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。