我有一个托管在 IIS 服务器中的应用程序,域为 https://example.com,但我无权访问其源代码。该应用程序有自己的身份验证机制。由于某些原因,我需要通过添加开发并生成 cookie 的 OTP 身份验证机制来为此应用程序添加额外的安全层。我在同一域中托管 OTP https://example.com/otp。
有没有办法阻止访问 https://example.com/login 并将其重定向到 OTP,除非用户在 OTP 中进行了身份验证并拥有有效的 cookie?
您可以尝试iis url重写规则来实现您的要求。以下是规则:
<rewrite>
<rules>
<rule name="test" stopProcessing="true">
<match url="(.*)" />
<action type="Redirect" url="https://example.com/otp" appendQueryString="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/login(.*)" />
<add input="{HTTP_COOKIE}" pattern="CookieName=*" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>
此规则会将登录页面重定向到 otp url。您必须在 iis url 重写规则中添加 HTTP_COOKIE 服务器变量。