如何为路由ASP.NET网页时不做工的Global.asax [英] How does routing for ASP.NET Web Pages work without global.asax
问题描述
与ASP.Net 4.0的Web服务器上安装,网页2.0的DLL仓部署。写在CSHTML /剃须刀,但路由的页面不工作。
Web server with ASP.Net 4.0 installed, Web Pages 2.0 DLLs bin deployed. Pages written in cshtml/razor, but routing is not working.
什么是需要在服务器上只使用网页时,而不是完整的MVC(其中我在Global.asax中定义了我的路线)来激活路由?
What is required on the server to activate routing when using only Web Pages as opposed to full MVC (where I'd have my routes defined in global.asax)?
现在我只能用传统的URL和查询字符串叫我的网页。
Right now I can only call my pages using the traditional URL and query string.
任何指针AP preciated。
Any pointers appreciated.
推荐答案
有两种路由提供的网页框架。默认的路由适用于匹配的URL到文件的路径。这是因为它允许为填充 UrlData code>词典额外的URL段相当灵活,而且可以使一些不错的SEO友好的URL结构。我已经写在这里: WebMatrix中 - 网址, UrlData和路由的搜索引擎优化。
There are two kinds of "routing" available in the Web Pages framework. The default routing works on matching URLs to file paths. It is quite flexible in that it allows for additional URL segments that populate a UrlData
dictionary, and can enable some nice SEO-friendly URL construction. I have written about that here: WebMatrix - URLs, UrlData and Routing for SEO.
第二种路由,这是类似的MVC中可用的路由需要一个包被安装:路由有关网页的。一旦你安装了这一点,你可以填充你的 RouteCollection
在_AppStart.cshtml文件(你需要自己创建),也可以在的Application_Start
在Global.asax中。你可以当你选择添加一个文件选择在选择文件类型对话框中的所有选项添加一个Global.asax文件。
The second kind of routing, which is similar to the routing available in MVC requires a package to be installed: Routing For Web Pages. Once you have installed this, you can either populate your RouteCollection
in an _AppStart.cshtml file (which you need to create yourself) or you can do so in Application_Start
in global.asax. You can add a global.asax file by selecting the All option in the Choose A File Type dialog when you choose to add a file.
如果你想知道如何使用路由包,我已经写它:的更多灵活的路由对于ASP.NET网页
If you want to know how to use the Routing package, I have written about that too: More Flexible Routing For ASP.NET Web Pages
这篇关于如何为路由ASP.NET网页时不做工的Global.asax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!