为什么URLRewriter.NET无法获取查询字符串值? [英] Why URLRewriter.NET doesn't get querystring values?
问题描述
我刚开始在博客中使用URLRewriter.net,但是在获取查询字符串值时遇到问题.我有一个规则设置,例如:
I just started using URLRewriter.net with my blog and I have a problem with getting the query string values. I have a rule setting like:
<rewrite url="~/blog.aspx(\?.+)?$"
to="~/hiddenFolder/blog.aspx?mode=default&$2"/>
但是当我尝试访问/blog.aspx?page=1时,未传递page参数.其他参数效果很好,并且重写规则没有冲突.
But when I try to access /blog.aspx?page=1 the page parameter is not passed. Other parameters work great and there are no conflicts in rewriting rules.
推荐答案
我认为问题在于$ 2超出范围,因为RegEx中只有一组.尝试$ 1.
I think the problem is that $2 is out of range as you only have one group in your RegEx. Try $1.
编辑
此外,可能是查询字符串附加了另一个'?'因此您需要将其移出括号.
In addition, it could be that the query string is being appended with another '?' so you need to move that out of the brackets.
您还需要一个额外的组,以使规则与不带'?'的规则匹配.注意:我们现在返回到结果$ 2:)
You'll also need an extra group to make the rule match with our without the '?'. Note: we're back to $2 in the result now :)
<rewrite url="~/blog.aspx(\?(.+)?)?$"
to="~/hiddenFolder/blog.aspx?mode=default&$2"/>
这篇关于为什么URLRewriter.NET无法获取查询字符串值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!