簡體   English   中英

IIS 重寫模塊 Windows 認證

[英]IIS Rewrite Module Windows Authentication

我有兩個 asp.net web 應用程序。 其中一個應用程序是主 mvc web 應用程序,第二個是 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 header 因為當授權 header 存在時,請求在身份驗證模塊運行之前被轉發,因此未設置身份驗證服務器變量(當映射到標頭時,它們只是通過空白出現)。

您可以使用自定義 HTTP 模塊,該模塊發送經過身份驗證的用戶自定義 header。

另一種方法是您可以設置 SPN:

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM