IIS重写模块Windows身份验证



我有两个asp.net web应用程序。其中一个应用程序是主mvc web应用程序,第二个应用程序作为反向代理,只包含一个文件web.config。反向代理没有启用任何身份验证模式,但主应用程序具有windows身份验证。当通过反向代理访问应用程序时,浏览器中会出现弹出窗口,要求提供windows凭据。是否可以以某种方式通过所有反向代理请求传递一个域用户?当反向代理重定向请求时,它会添加自定义标头。是否可以从iis池传递用户,或者以某种方式进行硬编码,以便所有反向代理请求都可以通过windows身份验证传递到主应用程序,然后用户可以通过正常登录页面进行身份验证?目标是通过反向代理访问主应用程序,而无需输入windows凭据。无法在主应用程序上禁用windows身份验证。谢谢你的回答。

反向代理web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)"/>
<action type="Rewrite" url="https://main-app.com/{R:1}"/>
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}"/>
<set name="HTTP_ACCEPT_ENCODING" value=""/>
<set name="HTTP_CUSTOM_ZEW_HEADER" value="True"/>
</serverVariables>
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^http(s)?://main-app.com/(.*)"/>
<action type="Rewrite" value="http{R:1}://main-app.com/{R:2}"/>
</rule>
<rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
<match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)"/>
<action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}"/>
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html"/>
</preCondition>
<preCondition name="NeedsRestoringAcceptEncoding">
<add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+"/>
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>

不可能转发REMOTE_USER标头,因为当存在Authorization标头时,请求会在身份验证模块运行之前转发,因此不会设置身份验证服务器变量(当映射到标头时,它们只是通过空白(。

您可以使用自定义HTTP模块来发送经过身份验证的用户自定义标头。

另一种方法是可以设置SPN:

https://learn.microsoft.com/en-us/archive/blogs/benjaminperkins/configure-application-request-routing-with-windows-authentication-kerberos

https://learn.microsoft.com/en-us/archive/blogs/asiatech/a-quick-solution-when-windows-authentication-is-required-on-backend-web-server-for-arr-scenario

最新更新