C# 如何在asp.net webforms中设置默认页面url路由
我正在尝试在weforms中实现url路由。我做了一部分。你能帮我把路由设置为起始页或索引页吗。在我的路线图课程中,我写了如下内容C# 如何在asp.net webforms中设置默认页面url路由,c#,asp.net,C#,Asp.net,我正在尝试在weforms中实现url路由。我做了一部分。你能帮我把路由设置为起始页或索引页吗。在我的路线图课程中,我写了如下内容 routes.MapPageRoute("Index","","~/Index.aspx"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "
routes.MapPageRoute("Index","","~/Index.aspx");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Student", action = "Index", id = UrlParameter.Optional }
);
我将Index.aspx设置为开始页并运行它。但url仍然是Index.aspx
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Student", action = "Index", id = UrlParameter.Optional }
);
在默认页面的MVC中,我们将编写如下所示的行集
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Student", action = "Index", id = UrlParameter.Optional }
);
在Webforms中是否有类似的技术??步骤
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Student", action = "Index", id = UrlParameter.Optional }
);
演练:在Web窗体应用程序中使用ASP.NET路由
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Student", action = "Index", id = UrlParameter.Optional }
);
已更新
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Student", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Student", action = "Index", id = UrlParameter.Optional }
);
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("Index","Index","~/Index.aspx");
}
我不认为这只能通过使用新的路由技术来实现,但您仍然可以通过在web.config中指定默认页面来实现。这可以通过添加以下内容作为
节点的子元素来实现(几乎在顶层):
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Student", action = "Index", id = UrlParameter.Optional }
);
然而,您的url将显示为yourdomain.com
,而不是yourdomain.com/Index.aspx
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Student", action = "Index", id = UrlParameter.Optional }
);
另一种选择是让您的
默认设置。aspx
页面永久重定向到索引
看看ScottGu@gkrishy routes的一篇非常好的文章RouteCollection@LibinCJacob如果你不使用MVC,你想要的东西可能做不到,因为在webforms中,每个视图/页面都有隐藏的代码,不像Controllers(在MVC中)@manish,实际上路由对我来说是有效的。我的问题是我无法在Webforms中设置默认页面路由。是的,我已经在我的项目中使用了上述代码。不working@LibinCJacob现在检查我的答案。我已经更新了。
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Student", action = "Index", id = UrlParameter.Optional }
);