asp.net – 如何设置MVC应用程序的默认页面?
发布时间:2020-12-15 23:16:36 所属栏目:asp.Net 来源:网络整理
导读:我想让我的基本URL去一个在线商店的特定类别(一个 NopCommerce在线商店,如果这有所作为).该类别的URL为:http://myUrl.com/c/6 在阅读包括Scott Gutherie的帖子about MVC routing在内的几篇帖子后,我以为我可以将以下代码添加到我的Global.ascx.cs文件中: p
我想让我的基本URL去一个在线商店的特定类别(一个
NopCommerce在线商店,如果这有所作为).该类别的URL为:http://myUrl.com/c/6
在阅读包括Scott Gutherie的帖子about MVC routing在内的几篇帖子后,我以为我可以将以下代码添加到我的Global.ascx.cs文件中: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); //register custom routes (plugins,etc) var routePublisher = EngineContext.Current.Resolve<IRoutePublisher>(); routePublisher.RegisterRoutes(routes); routes.MapRoute( "Default",// Route name "{controller}/{action}/{id}",// URL with parameters new { controller = "Catalog",action = "Category",id = 6 },new[] { "Nop.Web.Controllers" } ); } 但这似乎没有起作用.我该如何完成我想要做的事情? 我对MVC没有什么经验,所以我道歉,如果这没有任何意义. 解决方法
看起来像最有趣的位在nopcommerce源代码中.默认路由注册为
routes.MapLocalizedRoute("HomePage","",new { controller = "Home",action = "Index"},new[] { "Nop.Web.Controllers" }); 您将基本上希望先注册默认路由,然后注册自定义路由注释.应该最终看起来像这样: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default",// Route name "{controller}/{action}/{id}",// URL with parameters new { controller = "Catalog",new[] { "Nop.Web.Controllers" } ); routes.MapRoute( "CustomHome",// Route name "",// URL with parameters new { controller = "Catalog",new[] { "Nop.Web.Controllers" } ); //register custom routes (plugins,etc) var routePublisher = EngineContext.Current.Resolve<IRoutePublisher>(); routePublisher.RegisterRoutes(routes); } 第一条路线甚至不需要.我不确定.从未与nopcommerce合作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET MVC Web API2 AngularJS授权和身份验证
- asp.net-mvc – 在ASP.NET MVC中保护NullReferenceExceptio
- .net – 在没有区域的控制器中创建子文件夹
- asp.net – Web API 2 – ApiController.InternalServerErr
- ASP.NET MVC中的Session以及处理方式
- asp.net-mvc-4 – 在asp .net mvc 4中使用htmlhelper创建te
- SOAP系列目录
- asp.net-mvc-4 – Kendo模板条件格式化
- asp.net – 从div标签中引发回发事件
- ASP.Net MVC6是否支持OAuth 2承载令牌?
推荐文章
站长推荐
- asp.net-mvc-3 – Razor:隐藏密码控制(2页注册)
- asp.net-mvc – 标准ASP.NET MVC ModelBinder的文
- asp.net-mvc – 将下拉列表中的SelectedItem绑定
- asp.net – 在web.config中将子文件夹重写为子域
- asp.net-core – 用于Core的DocumentDB Transien
- asp.net-mvc – 如何在VS2008 Web Devloper Expr
- asp.net-mvc-3 – MVC3 Html.BeginForm – 在Rou
- .net – REST API:与身体的GET请求
- asp.net-mvc-3 – 在同一父视图上多次使用一个部
- 如何在服务器上安装ASP.NET MVC 5?
热点阅读