网址重写-REMOTE_USER始终为空 [英] URL rewrite - REMOTE_USER always empty
问题描述
我需要创建一个URL重写规则,将REMOTE_USER值添加到查询字符串中.我将我的应用程序简化为绝对必要的内容.但是,在评估规则条件时,REMOTE_USER始终为空.
I need to create a URL rewrite rule that adds the REMOTE_USER value to the query string. I simplified my app down to absolute essentials. However, the REMOTE_USER is always empty while the rule condition is evaluated.
我在IIS 7中配置的网站,应用程序池使用了与.NET 2.0集成的模式.我通过IIS管理器禁用了匿名身份验证并在站点上启用了Windows身份验证,甚至将行添加到web.config中以防止匿名访问.这是我的两个文件.
My web site configured in IIS 7, app pool uses integrated mode with .NET 2.0. I disabled Anonymous Auth and enabled Windows Auth on the site through IIS Manager and I even added the line to web.config to prevent anonymous access. Here are my two files.
web.config:
web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<authorization>
<remove users="?" roles="" verbs="" />
</authorization>
</security>
<rewrite>
<rules>
<clear />
<rule name="Add login into URL" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="login" negate="true" />
<add input="{REMOTE_USER}" pattern="(.*)" />
</conditions>
<action type="Redirect" url="{HTTP_URL}?login={C:1}" redirectType="Temporary" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
default.asp
default.asp
<%= Request.ServerVariables("REMOTE_USER") %>
我的规则永远不会生效,因为在评估条件时{REMOTE_USER}始终为空白(其他服务器变量显示在规则中,因此仅为{REMOTE_USER}).不同之处在于default.asp显示了我的REMOTE_USER值.
My rule never hits because {REMOTE_USER} is always blank when conditions are evaluated (other server variables show up in the rule, so it's just {REMOTE_USER}). The twist is that default.asp shows my REMOTE_USER value.
有人建议为什么会这样吗?谢谢
Any suggestions why this happened? Thank you
推荐答案
我不知道为什么以前没有找到此链接.正如我所怀疑的那样,auth在URL重写规则之后运行,并且REMOTE_USER无法用于重定向.我想我必须编写自己的重定向模块.
I don't know why I didn't find this link before. As I suspected, auth runs after URL rewrite rules and REMOTE_USER can't be used to redirect. I suppose I would have to write my own redirection module.
http://forums.iis.net/t/1155169.aspx/1
这篇关于网址重写-REMOTE_USER始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!