IIS7 上的 URL 重写

发布于 2024-12-16 12:04:57 字数 400 浏览 1 评论 0原文

我正在尝试使用 IIS 上的入站规则将 URL 重写为另一个 URL。我想做的基本上是任何类似于 localhost/Membership/Login 的请求都将是 localhost/handlers/mapper.ashx?url=Membership/Login 。我所做的是创建一个如下所示的模式

(Membership\/)(.+)

,重写网址

http://localhost/handlers/mapper.ashx?url={R:0}

实际上是这种方式并没有给我我想要的解决方案。它会像正常请求一样继续工作,不会发送到mapper.ashx。

可能是什么问题?做这样的事情的正确方法是什么?

提前致谢,

I am trying to rewrite a url to a different one by using inbound rule on IIS. What I am trying to do is basically any request thats like localhost/Membership/Login will be localhost/handlers/mapper.ashx?url=Membership/Login. What I have done is creating a pattern something like below

(Membership\/)(.+)

and the rewrite url is

http://localhost/handlers/mapper.ashx?url={R:0}

Actually this way did not give me the solution what I want. It keeps working as a normal request not goes to the mapper.ashx.

What can be the problem ? What is the proper way to do something like that ?

Thanks in advance,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三月梨花 2024-12-23 12:04:57

正如达拉斯已经指出的那样,你要求的东西不是你自己的解决方案所建议的。但我会给你两种选择。首先,如果您只需要 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>

As Dallas already pointed out you ask for something else than what your own solutions suggests. But I will give you both options. First of all, if you just need the login part of the URL as a methodname parameter for your handler you can use the following rewrite rule:

<rule name="Rewrite to handler" stopProcessing="true">
    <match url="^Membership/(.+)" />
    <action type="Rewrite" url="/handlers/mapper.ashx?methodname={UrlEncode:{R:1}}" appendQueryString="false" />
</rule>

If you need the complete URL in the url parameter as your own solution suggests then you can use the following rewrite rule:

<rule name="Rewrite to handler" stopProcessing="true">
    <match url="^Membership/(.+)" />
    <action type="Rewrite" url="/handlers/mapper.ashx?url={UrlEncode:{R:0}}" appendQueryString="false" />
</rule>
歌入人心 2024-12-23 12:04:57

这并不能解释为什么您的映射被跳过,但您的示例和实际实现是不同的。您说您希望将请求映射到

localhost/handlers/mapper.ashx?methodname=Login

但您的重写网址示例是

http://localhost/handlers/mapper.ashx?url={R:0}

您的重写网址中有网址,而不是方法名

This doesn't explain why your mapping is being skipped but your example and actual implementation are different. You say you want the requests mapped to

localhost/handlers/mapper.ashx?methodname=Login

but your example for rewrite url is

http://localhost/handlers/mapper.ashx?url={R:0}

You have url in your rewrite url, not methodname

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文