问题描述
限时送ChatGPT账号..如何将 url 路由到 .cshtml 页面?例如.www.example/view/2 --> view.cshtml
How can I route an url to a .cshtml page? E.g. www.example/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/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/Article/165/WebMatrix-URLs-UrlData-and-Routing-for-SEO
如果要映射与磁盘上文件不匹配的 url,可以使用 Nuget 包 (http://www.nuget/packages/WebPageRouteHandler/).它有点复杂,但我也写了一篇关于如何使用它的文章:http://www.mikesdotnetting/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/packages/WebPageRouteHandler/). It's a bit more complicated, but I have written an article about how to use that too: http://www.mikesdotnetting/Article/187/More-Flexible-Routing-For-ASP.NET-Web-Pages
这篇关于没有 MVC 的 URL 路由 ASP.NET 网页 (.cshtml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论