我试图通过在IIS上使用入站规则将url重写为不同的url。我想做的是,基本上任何请求,比如localhost/Membership/Login
,都会变成localhost/handlers/mapper.ashx?url=Membership/Login
。我所做的就是在
(Membership/)(.+)
,重写url为
http://localhost/handlers/mapper.ashx?url={R:0}
其实这种方法并没有给我想要的答案。它继续作为一个正常的请求工作,而不是转到mapper.ashx。
有什么问题吗?怎么做才是正确的呢?
提前致谢
正如Dallas已经指出的那样,你要求的不是你自己的解决方案所建议的。但我会给你两种选择。首先,如果您只需要URL的login
部分作为处理程序的methodname
参数,您可以使用以下重写规则:
<rule name="Rewrite to handler" stopProcessing="true">
<match url="^Membership/(.+)" />
<action type="Rewrite" url="/handlers/mapper.ashx?methodname={UrlEncode:{R:1}}" appendQueryString="false" />
</rule>
如果您需要url
参数中的完整URL,那么您可以使用以下重写规则:
<rule name="Rewrite to handler" stopProcessing="true">
<match url="^Membership/(.+)" />
<action type="Rewrite" url="/handlers/mapper.ashx?url={UrlEncode:{R:0}}" appendQueryString="false" />
</rule>
这并不能解释为什么您的映射被跳过,但您的示例和实际实现是不同的。你说你想把请求映射到
localhost/处理/mapper.ashx吗? methodname =登录
但是你重写url的例子是
http://localhost/handlers/mapper.ashx?= {R: 0}
你的重写url中有url,而不是methodname