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.
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)?
Right now I can only call my pages using the traditional URL and query string.
Any pointers appreciated.
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
UrlDatadictionary, and can enable some nice SEO-friendly URL construction. I have written about that here: WebMatrix – URLs, UrlData and Routing for SEO.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
RouteCollectionin an _AppStart.cshtml file (which you need to create yourself) or you can do so inApplication_Startin 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.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