首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ASP.基于Web表单的网络路由?

ASP.基于Web表单的网络路由?
EN

Stack Overflow用户
提问于 2017-12-27 04:10:18
回答 2查看 0关注 0票数 0

有没有人使用ASP。用简单的方式使用web表单进行网络路由?有什么事情需要注意吗?有没有可能遇到性能问题?

EN

回答 2

Stack Overflow用户

发布于 2017-12-27 12:32:44

您可以在下面的文章中找到以简单方式解释的URL路由。它提供了如下信息:在路由上发送请求,在目标页面上检索URL参数,设置参数的默认值。

ASP中的URL路由。NETWeb窗体第1部分

ASP中的URL路由。NET Web窗体第2部分

票数 0
EN

Stack Overflow用户

发布于 2017-12-27 13:17:20

关于如何在ASP中使用路由的简单示例。网

  1. 创建空Web应用程序
  2. 添加第一个表单-Default.aspx
  3. 添加第二个表单-Second d.aspx
  4. 添加第三种形式-第三种形式
  5. 添加到default.aspx 3按钮-

protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("Second.aspx"); } protected void Button2_Click(object sender, EventArgs e) { Response.Redirect("Third.aspx?Name=Pants"); } protected void Button3_Click(object sender, EventArgs e) { Response.Redirect("Third.aspx?Name=Shoes"); }

  1. 读取第三页上的查询字符串protected void Page_Load(object sender, EventArgs e) { Response.Write(Request.QueryString["Name"]); }现在,如果您运行该程序,您将能够导航到五表单。以前是这样的。让我们加上路由。
  2. 添加新项目-Global.aspx使用系统。

protected void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); } void RegisterRoutes(RouteCollection routes) { routes.MapPageRoute( "HomeRoute", "Home", "~/Default.aspx" ); routes.MapPageRoute( "SecondRoute", "Second", "~/Second.aspx" ); routes.MapPageRoute( "ThirdRoute", "Third/{Name}", "~/Third.aspx" ); }

  1. 在default.aspx中修改受保护的voidButton 1[医]单击(对象发送方,EventArgs e){//Response.redirect(“Second d.aspx”);响应。重定向(GetRouteUrl(“备用路线”,NULL));}protected void Button2_Click(object sender, EventArgs e) { //Response.Redirect("Third.aspx?Name=Pants"); Response.Redirect(GetRouteUrl("ThirdRoute", new {Name = "Pants"})); } protected void Button3_Click(object sender, EventArgs e) { // Response.Redirect("Third.aspx?Name=Shoes"); Response.Redirect(GetRouteUrl("ThirdRoute", new { Name = "Shoes" })); }
  2. 修改第三版中的页面加载

protected void Page_Load(object sender, EventArgs e) { //Response.Write(Request.QueryString["Name"]); Response.Write(RouteData.Values["Name"]); }

运行程序,请注意,url看起来要干净得多--其中没有文件扩展名(Secd.aspx仅为第二位)

  1. 通过不止一个论点
    • 使用以下代码向default.aspx添加新按钮:

protected void Button4_Click(object sender, EventArgs e) { Response.Redirect(GetRouteUrl("FourthRoute", new { Name = "Shoes" , Gender = "Male"})); }

代码语言:txt
复制
- add the following code to global.asax
 `routes.MapPageRoute(       "FourthRoute",       "Fourth/{Name}-{Gender}",       "~/Fourth.aspx"   );` 
- create Fourth.aspx page with the following page load:

protected void Page_Load(object sender, EventArgs e) { Response.Write("Name is: " + RouteData.Values["Name"] + " and Gender is " + RouteData.Values["Gender"]); }

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100000039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档