开发者

asp.net consecutive are backslashes removed from url

开发者 https://www.devze.com 2023-01-22 21:47 出处:网络
I\'m having an issue in my ASP.NET web app where intentionally consecutive backslashes are being removed from the request url.

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!!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消