如何在mvc中路由,如何在mvc中隐藏页面扩展名?

问题描述:

我有网站,我有一个名为test.html页面的页面。当我浏览http://www.domainName.com/test时,它会选择test.html页面而不使用控制器和操作方法。如何在mvc中路由,如何在mvc中隐藏页面扩展名?

什么我routeconfig.cs写

routes.MapRoute(
       name: "", 
       url: "", 
       defaults: new 
       { 

       }); 

你可以achive它在两个方面

在你的路由配置:

routes.MapPageRoute("Yourhtmlroute","Yourcustomurl","Path/To/Your/test.html"); 

在控制器:

return Redirect("YourCustomUrl"); 
+0

if **“Path/To/Your/test.html”**是html文件路径,那么**“Yourhtmlroute”**是什么? –

+0

http://localhost/smartpond/MyPage.html(working),但http:// localhost/smartpond/MyPage不工作 routes.MapPageRoute(“MyPage.html”,“MyPage”,“〜/ MyPage.html” ); – Swapna

+0

错误 - VirtualPath必须是以〜/开头的非空字符串。 参数名称:virtualPath – Swapna