asp.net 4.0 Web 表单路由 - 默认/通配符路由
在使用 ASP.NET 4.0 路由与 Web 窗体来生成充当某种通配符的路由时,有一种简单的方法吗?
在我看来,在 WebForms 中,您必须为每个页面指定一个路由 - 我正在寻找某种通用路由,可以在不需要任何特定内容的情况下使用,也许直接从路径映射到路径,所以...
http://somedomain.com/folder1/folder2/page 可能会映射到folder1/folder2/page。 aspx
有什么建议吗?
谢谢
I there a simple way when using ASP.NET 4.0 routing with Web Forms to produce a route that will act as some kind of wildcard?
It seems to me that within WebForms, you have to specify a route for every page - I am looking for some kind of generic route that can be used where nothing specific is required, perhaps mapping directly from path to path so...
http://somedomain.com/folder1/folder2/page would possibly map to folder1/folder2/page.aspx
Any suggestions?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以像这样匹配所有剩余的路由:
在这种情况下,我们知道所有路由,并且希望将其他任何内容发送到“丢失”/404 页面。请务必将其作为最后路线,因为它是通配符并且会捕获所有内容。
或者,您可以以相同的方式注册路线,但在内部映射到页面,如下所示:
该处理程序类将执行通配符映射,如下所示:
这在奇怪的地方有点破坏,以防止水平滚动,但您会得到总体要点。再次确保这是最后路线,否则它将处理您的所有路线。
You can match all remaining routes like this:
In this case, we know all routes, and want to send anything else to a "missing"/404 page. Just be sure to put this as the last route, since it is a wildcard and will catch everything.
Alternatively you could register a route the same way, but internally does mapping to a page, like this:
That handler class would do your wildcard mapping, something like this:
This is broken a bit in odd places to prevent horizontal scrolling, but you get the overall point. Again, make sure this is the last route, otherwise it'll handle all your routes.
另外 - 请记住,如果您的 Web 应用程序中有验证控件,则需要在 Global.asax 文件中为 .axd 文件添加例外:
http://basgun.wordpress.com/2010/10/25/getting -syntax-error-in-asp-net-routing-due-to-webresource-axd/
否则,您将不断收到语法错误,因为路由选择 .axd 文件并且无法正确加载 JavaScript 文件验证控制所需的。
Additionally - Keep in mind that you need to add an exception for the .axd files in your Global.asax file if there are validation controls in your web app:
http://basgun.wordpress.com/2010/10/25/getting-syntax-error-in-asp-net-routing-due-to-webresource-axd/
Otherwise, you will keep getting a syntax error because the routing picks up the .axd files and not properly loads the JavaScript files needed for the validation controls.