是否可以从ASP.NET MVC中的URL中删除文件夹?

时间:2016-06-08 08:27:30

标签: asp.net asp.net-mvc iis windows-server-2012

是否可以从网址中删除文件夹,以便 domain.com/mvc/page / 变为 domain.com/page/

这是在带有IIS 7.5的Windows Server 2012上运行的ASP.NET 4.5 MVC应用程序

编辑:

/ mvc /是包含MVC Web应用程序的文件夹,位于URL domain.com/mvc/page/whatever/else /

2 个答案:

答案 0 :(得分:0)

问我记得MVC中的URL不依赖于文件夹结构,而是依赖于Controller和Routing。(属性路由)

 routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

。请检查此链接。 ASP.NET MVC Routing Overview (C#)。我想你可以在那里找到更多解释。 对于一个链接,您可以使用属性

[Route("orders/{id:int}/{orderCode?}")]
    public async Task<ActionResult> Order(int id, string orderCode = "")
    {
   ////
    }

答案 1 :(得分:0)

  

是否可以从ASP.NET MVC中的URL中删除文件夹?

没有。

MVC不使用文件和文件夹来托管其端点 - 它使用控制器和操作。因此,无法删除&#34;文件夹&#34;来自URL,因为URL中没有文件夹。

但是,MVC使用.NET路由,它允许您根据需要配置URL。因此,要根据您的示例创建与public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // Route to domain.com/page that calls an action named Page on the HomeController routes.MapRoute( name: "PageRoute", url: "page", defaults: new { controller = "Home", action = "Page" } ); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } } 匹配的路由,您需要插入路由以将该URL与MAX(Products.AvailableDate) > CURDATE() As IsEarlyAccess 文件匹配。

MAX(Products.AvailableDate > CURDATE()) As IsEarlyAccess