c# - IIS 重写模块 Windows 身份验证
问题描述
我有两个 asp.net web 应用程序。其中一个应用程序是主 mvc Web 应用程序,第二个是充当反向代理的 Web 应用程序,仅包含一个文件 - web.config。反向代理没有启用任何身份验证模式,但主应用程序具有 Windows 身份验证。通过反向代理访问应用程序时,浏览器中会出现弹出窗口,要求您提供 Windows 凭据。是否可以通过所有反向代理请求以某种方式传递一个域用户?当反向代理重定向请求时,它会添加自定义标头。是否可以从 iis 池传递用户或以某种方式硬编码,以便所有反向代理请求都可以通过 windows auth 传递到主应用程序,然后用户可以通过正常登录页面进行身份验证?目标是通过反向代理访问主应用程序,而无需输入 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:
推荐阅读
- ckeditor - #9073 ImageUpload 回调不能跨域调用 CKEditor
- r - 如何在 R 中提取两列数据
- roblox - Roblox 中的排行榜类而不是 KO
- javascript - 组合html文档时JavaScript计算输出错误(html干扰?)
- r - overlay() 函数中的错误,用 R 中的栅格和数值计算
- javascript - 数组架构上的 Node.js RESTful API 验证错误
- typescript - 语法高亮适用于 gvim(vim 的 GUI 版本)但不适用于 vim(基于终端的 vim)
- matlab - 如何避免 parfor 循环中的变量广播?
- sql - Hive 中的列到行
- javascript - Android 如何在 WebView 中显示来自原始 html 和 javascrip 脚本的文件