了解路由在Global.asax中(asp.net,MVC) [英] Understanding routing in Global.asax (asp.net-mvc)

查看:161
本文介绍了了解路由在Global.asax中(asp.net,MVC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Global.asax中哪些呢下面意味着什么?

  routes.IgnoreRoute({}资源个.axd / {*} PATHINFO);


解决方案

这是有关学习MVC真正令人沮丧的事情之一 - 该功能的文档是可怕的 - 但只是几乎没有什么有:<一href=\"http://msdn.microsoft.com/en-us/library/dd470170(VS.100).aspx\">http://msdn.microsoft.com/en-us/library/dd470170(VS.100).aspx.

  routes.IgnoreRoute({}资源个.axd / {*} PATHINFO);

这允许所有something.axd文件MVC外运行 - 即{*} PATHINFO末允许查询字符串被忽略(这是种通配符)

请注意,这并不任何这种通配符适用于路径中,所以

 的trace.axd?清晰= 1 //排除MVCmySubFolder / customResource.axd // MVC传递给mySubFolderController.customResource()

帮助。我一直无法找到到底是什么,不支持从关键字除了任何体面的文件{}资源和{*} PATHINFO

不过有一个几乎完全无证功能,让您对这些被忽略的路线更多的控制:

  //忽略所有的WebForms的.aspx /的.asmx / .ashx的任何地方调用
routes.IgnoreRoute({*} allaspx,新{allaspx = @* \\为[PMH]×(/.*)。?});

如果您通过使用属性的匿名初始化的对象,该属性就可以在路由使用关键字。

您不能传递一个正则表达式的路线,但你可以在这个匿名属性。

In Global.asax what does the following signify?

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");     

解决方案

This is one of the really frustrating things about learning MVC - the documentation for this feature is awful - there's just hardly anything there: http://msdn.microsoft.com/en-us/library/dd470170(VS.100).aspx.

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

This allows all the something.axd files to run outside of MVC - that "{*pathInfo}" at the end allows query strings to be ignored (it's kind of a wildcard).

Note that this doesn't apply any such wildcard to the path, so:

trace.axd?clear=1 //excluded from MVC

mySubFolder/customResource.axd //MVC passed to mySubFolderController.customResource()

Helpful. I've been unable to find any decent documentation on exactly what is and isn't supported as keywords apart from "{resource}" and "{*pathInfo}"

However there is an almost completely undocumented feature that gives you a lot more control over these ignored routes:

//ignore all WebForms .aspx/.asmx/.ashx calls anywhere
routes.IgnoreRoute( "{*allaspx}", new { allaspx = @".*\.as[pmh]x(/.*)?" } );

If you pass an anon-initialised object with a property, that property becomes a keyword that you can use in the route.

You can't pass a regex in the route, but you can in this anon property.

这篇关于了解路由在Global.asax中(asp.net,MVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆