没有 MVC 的 URL 路由 ASP.NET 网页 (.cshtml) [英] Url Routing ASP.NET WebPages (.cshtml) without MVC

查看:34
本文介绍了没有 MVC 的 URL 路由 ASP.NET 网页 (.cshtml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 url 路由到 .cshtml 页面?例如.www.example.com/view/2 --> view.cshtml

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

我不想使用 MVC,最好不要用控制器代码和其他东西使事情复杂化.只是一个尽可能简单的路由.

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.

推荐答案

简单的路由,例如您只想访问现有文件名而无需扩展名的简单路由,默认情况下在 Web Pages 站点中有效.2 可在 UrlData 集合中访问.

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.

这是一篇解释基本路由系统在网页中的工作原理的文章:http://www.mikesdotnetting.com/Article/165/WebMatrix-URLs-UrlData-and-Routing-for-SEO

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

如果要映射与磁盘上文件不匹配的 url,可以使用 Nuget 包 (http://www.nuget.org/packages/WebPageRouteHandler/).它有点复杂,但我也写了一篇关于如何使用它的文章:http://www.mikesdotnetting.com/Article/187/More-Flexible-Routing-For-ASP.NET-Web-Pages

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

这篇关于没有 MVC 的 URL 路由 ASP.NET 网页 (.cshtml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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