asp.net – 如何设置MVC应用程序的默认页面?
发布时间:2020-05-24 03:19:24 所属栏目:asp.Net 来源:互联网
导读:我想让我的基本URL去一个在线商店的特定类别(一个 NopCommerce在线商店,如果这有所作为).该类别的URL为:http://myUrl.com/c/6 在阅读包括Scott Gutherie的帖子about MVC routing在内的几篇帖子后,我以为我可以将以下代码添加到我的Global.ascx.cs文件中: pu
|
我想让我的基本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 4.0的DotNetOpenAuth
- asp.net-mvc – 如何告诉Ninject绑定到它没有引用的实现
- .net – 单元测试api控制器的示例代码
- ASP.NET Web应用程序(MVC)部署自动化和Subversion
- asp.net-mvc – 在Html.ActionLink的linkText中使用HTML标签
- 当调用ASP.NET System.Web.HttpResponse.End()时,当前线程中
- asp.net – Databinder.Eval和Container.DataItem有什么区别
- ASP.NET – IIS7 – IBM DB2问题
- asp-classic – 如何在asp页面中以编程方式301重定向?
- asp.net-mvc-4 – 如何获取没有隐藏输入的AntiForgeryToken
推荐文章
站长推荐
- asp.net-mvc-3 – 如何在Asp.Net Mvc 3中显示自定
- asp.net-mvc – ASP.NET MVC快速启动 – 一站式教
- asp.net-mvc – 没有值的asp.net mvc htmlattrib
- asp.net-mvc – 在哪里?Json.Encode或@Json.Dec
- 实体框架 – 使用EF和WebAPI,如何返回一个ViewMo
- 应该在ASP.NET页面中完成哪些操作?
- asp.net-mvc – Css和脚本不工作,直到用户登录网
- asp.net-core – 如何从MVC 6中的ASP.Net 5 Tag
- asp.net – Helios项目的当前状态是什么?
- asp.net-mvc-3 – 在哪里可以找到MvcTextTemplat
热点阅读
