没有 MVC 的 URL 路由 ASP.NET 网页 (.cshtml)

编程入门 行业动态 更新时间:2024-10-11 23:20:25
本文介绍了没有 MVC 的 URL 路由 ASP.NET 网页 (.cshtml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-28 13:04:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1173698.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   网页   URL   MVC   cshtml

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!