Url Routing ASP.NET WebPages (.cshtml) without MVC

僤鯓⒐⒋嵵緔 提交于 2019-12-11 09:04:34

问题


How can I route an url to a .cshtml page? E.g. www.example.com/view/2 --> view.cshtml

I don't want to use MVC and preferably not complicate things with controller code and other stuff. Just a routing as simple as possible.


回答1:


Simple routes like the one where you just want to reach an existing file name without the extension work by default in a Web Pages site. The 2 is accessible in the UrlData collection.

Here's an article that explains how the rudimentary routing system works in Web Pages: http://www.mikesdotnetting.com/Article/165/WebMatrix-URLs-UrlData-and-Routing-for-SEO

If you want to map a url that doesn't match a file on disk, you can use a Nuget package (http://www.nuget.org/packages/WebPageRouteHandler/). It's a bit more complicated, but I have written an article about how to use that too: http://www.mikesdotnetting.com/Article/187/More-Flexible-Routing-For-ASP.NET-Web-Pages



来源:https://stackoverflow.com/questions/18480999/url-routing-asp-net-webpages-cshtml-without-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!