如何在 mvc 中进行路由,如何在 mvc 中隐藏页面扩展名?
how to do routing in mvc , how to hide page extension name in mvc?
我有网站和一个名为 test.html 的页面。当我浏览 http://www.domainName.com/test 时,它应该在不使用控制器和操作方法的情况下选择 test.html 页面。
我要写什么routeconfig.cs
routes.MapRoute(
name: "",
url: "",
defaults: new
{
});
你可以通过两种方式实现它
在您的路由配置中:
routes.MapPageRoute("Yourhtmlroute","Yourcustomurl","Path/To/Your/test.html");
和
在您的控制器中:
return Redirect("YourCustomUrl");
我有网站和一个名为 test.html 的页面。当我浏览 http://www.domainName.com/test 时,它应该在不使用控制器和操作方法的情况下选择 test.html 页面。
我要写什么routeconfig.cs
routes.MapRoute(
name: "",
url: "",
defaults: new
{
});
你可以通过两种方式实现它
在您的路由配置中:
routes.MapPageRoute("Yourhtmlroute","Yourcustomurl","Path/To/Your/test.html");
和
在您的控制器中:
return Redirect("YourCustomUrl");