Barış Velioğlu
Barış Velioğlu

Reputation: 5827

Url Rewriting on IIS7

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,

Upvotes: 0

Views: 523

Answers (2)

Marco Miltenburg
Marco Miltenburg

Reputation: 6138

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>

Upvotes: 2

Dallas
Dallas

Reputation: 2237

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

Upvotes: 0

Related Questions