【发布时间】:2023-03-24 21:55:01
【问题描述】:
我对 MVC 路由感到困惑。假设我有这个域:poopoopants.com。我想要一些来自根目录的标准 URL,它们可以转到“关于”页面或“联系”页面:
http://poopoopants.com/about
http://poopoopants.com/contact
现在,我还将在下面有无限数量的这两条路线,其中“[user]”是在 poopoopants.com 上注册帐户的人的用户名的变量,而 [file-path ] 是一个 URL 清理文件路径可能包含 / 字符:
http://poopoopants.com/[user]
http://poopoopants.com/[user]/[file-path]
所以我假设我有一个IndexController 和一个Index 操作用于/,About 操作用于/about,Contact 操作用于/contact,还有一个UserController对/[user]/ 使用Index 操作,对/[user]/[file-path] 使用File 操作。
我的问题与Global.asax.cs 中的明确路线有关。到目前为止,我得到了:
routes.MapRoute("Index", "/", new { controller = "Index", action = "Index" });
routes.MapRoute("About", "/about", new { controller = "Index", action = "About" });
routes.MapRoute("Contact", "/contact", new { controller = "Index", action = "Contact" });
但是我为 /[user] 和 /[user]/[file-path] 路由指定了什么,它们在UserController 中的操作的相应方法签名是什么?
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-routing