ASP.NET UrlRewriter - 如何为根编写正则表达式?
我一直在尝试在测试项目中使用 UrlRewriter (Intelligencia.UrlRewriter.dll)。
我的重写语句如下:
<rewrite url="~/Sample/(.+)" to="~/Sample.aspx?Test=$1"/>
该语句非常适合类似以下的 URL:
http://localhost:4188/RewriteTest/Sample/12345
或者,比方说:
http://RewriteTest.com/Sample/12345
而且,我可以在 Sample.aspx 文件中检索值“12345”:
Label1.Text = "Test: " + Request.QueryString["Test"];
当我点击根链接时,它成功了显示 Default.aspx:
http://localhost:4188/RewriteTest/
或 http://RewriteTest.com/
我想要完成的是获取“样本”关闭正则表达式语句,以便我可以直接点击 http://RewriteTest.com/12345
并通过检索“12345”值来显示 Sample.aspx。而且,当根目录被点击http://RewriteTest.com/
时,它只会像现在一样显示Default.aspx。
是否可以?为此目的,可以将正则表达式语句更新为其他内容吗?
谢谢你,
尼亚兹
I have been trying to use UrlRewriter (Intelligencia.UrlRewriter.dll) in a test project.
My rewrite statement is as in the following:
<rewrite url="~/Sample/(.+)" to="~/Sample.aspx?Test=$1"/>
This statement works great for a URL like:
http://localhost:4188/RewriteTest/Sample/12345
or, let's say:
http://RewriteTest.com/Sample/12345
And, I can retrieve the value "12345" in Sample.aspx file as:
Label1.Text = "Test: " + Request.QueryString["Test"];
And when I hit the root link, it successfully displays the Default.aspx:
http://localhost:4188/RewriteTest/
or http://RewriteTest.com/
What I want to accomplish is taking the "Sample" off the regex statement, so that I can directly hit http://RewriteTest.com/12345
and display Sample.aspx by retrieving "12345" value. And, when the root is hit http://RewriteTest.com/
it will simply display Default.aspx as it is now.
Is it possible? Can the regex statement be updated to something else for this purpose?
Thank you,
Niyazi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的 ID 代码始终是 5 位数字,那么您可以将正则表达式限制为:
或可变长度数字:
If your ID code is always going to be 5 digit number then you could have clamped the regex to that:
Or a variable length number: