[英]How to set the default page url routing in asp.net webforms
I am trying to implement the url routing in my weforms. 我正在尝试在我的weforms中实现url路由。 I've did it partially.
我已经部分地做了。 Could you please help me to set the routing to the initial page or the index page.
你能帮我把路由设置到初始页面或索引页面吗? In my route map class I've written as following
在我的路线图类中,我写了如下
routes.MapPageRoute("Index","","~/Index.aspx");
and I set as the Index.aspx as the set as start page and run it. 然后我将Index.aspx设置为起始页面并运行它。 But still the url is Index.aspx.
但仍然是网址是Index.aspx。
In MVC for the default page we will write the set of lines as below. 在默认页面的MVC中,我们将编写一组行,如下所示。
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Student", action = "Index", id = UrlParameter.Optional }
);
In Webforms Is there any technique like this??? 在Webforms中有没有像这样的技术?
Try in this way, 试试这种方式,
Updated 更新
physicalFile : The URL of the actual ASP.Net Page where the Route URL should redirect to. physicalFile :Route URL应重定向到的实际ASP.Net页面的URL。 For this example it is Customers.aspx.
对于此示例,它是Customers.aspx。 The MapPageRoute method adds the Route to the Global Route collection ie RouteTable.Routes.
MapPageRoute方法将Route添加到Global Route集合,即RouteTable.Routes。 The RegisterRoutes is called inside the Application_Start event handler so that all the routes are added the RouteTable collection when the application starts.
在Application_Start事件处理程序内部调用RegisterRoutes,以便在应用程序启动时将所有路由添加到RouteTable集合中。 That's all you need to do the remove or hide the .ASPX extension of the ASP.Net Web Page, now if you type in the URL as http://localhost:1932/RoutingCS/Customers/ or http://localhost:1932/RoutingCS/Customers both will redirect you to the customers page ie Customers.aspx.
现在,如果您输入URL作为http:// localhost:1932 / RoutingCS / Customers /或http:// localhost:1932 ,那么您只需删除或隐藏ASP.Net网页的.ASPX扩展名即可。 / RoutingCS / Customers都会将您重定向到客户页面,即Customers.aspx。
protected void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); } public static void RegisterRoutes(RouteCollection routes) { routes.MapPageRoute("Index","Index","~/Index.aspx"); }
For steps Click Here 对于步骤单击此处
Walkthrough: Using ASP.NET Routing in a Web Forms Application 演练:在Web窗体应用程序中使用ASP.NET路由
I don't think this can be done using the new routing techniques only, but you still can do it by specifying the default page in your web.config. 我不认为这只能使用新的路由技术来完成,但您仍然可以通过在web.config中指定默认页面来实现。 This can be done by adding the following as a child element of the
<configuration>
node (almost at top level) : 这可以通过添加以下作为
<configuration>
节点的子元素(几乎在顶层)来完成:
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear />
<add value="Index.aspx" />
</files>
</defaultDocument>
</system.webServer>
Nevertheless, your url will display as yourdomain.com
and not as yourdomain.com/Index.aspx
不过,您的网址将显示为
yourdomain.com
而不是yourdomain.com/Index.aspx
Another alternative is to have your Default.aspx
page do a permanent redirect to Index
另一种方法是让
Default.aspx
页面永久重定向到Index
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.