views:

21

answers:

1

I'm having an issue in my ASP.NET web app where intentionally consecutive backslashes are being removed from the request url.

I'll request something like: localhost/Page/A//C

But when the request hits the page, the raw url is: localhost/Page/A/C

Not sure if this is the culprit, but I do have a Url Rewite regex in place, here's the rule:

   <system.webServer>
        <rewrite>
            <rules>
                <rule name="Games QueryString">
                  <match url="^(Page|OtherPage).aspx(?:/([\w-_()]+)(?:/([\w-_() ]*)(?:/([\w-_()]+))?)?)?$" />
                  <action type="Rewrite" url="{R:1}.aspx?1={R:2}&amp;2={R:3}&amp;3={R:4}" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>

So, after the rewrite, the querystring is coming out as Page.aspx?1=A&2=C&3= When it should be Page.aspx?1=A&2=&3=C

Help please!!

A: 

You could probably change your regex to something like this:

^(Page|OtherPage).aspx(?:/+([\w-_()]+)(?:/+([\w-_() ]*)(?:/+([\w-_()]+))?)?)?$

I have added a "+" after your matches to "/", which changes them from accepting a single "/" to accepting one or more.

Also, I cannot work out for the life of my why you'd want to have extra slashes in there. Probably a bad idea. Reconsider doing that for any reason.

nizmow
JoshKraker