ASP.NET WebForms 4.0支持单向路由功能(MVC)

简介:

The ASP.NET Routing engine was added in .NET Framework 3.5 SP1. Now Microsoft have added better support for using the engine in ASP.NET WebForms 4.0 by using expression builders enabling bi-directional routing.

Channel9 have just published a new episode of 10-4 showing how to use this new functionality in ASP.NET 4.0. In the video Jonathan Carter walk through a simple example of how to enable this in an existing ASP.NET application.

Below is a summary of the code showed in the video. They use the typical example of how Product.aspx?category=jerseys can map to Product/Jerseys. Using the ASP.NET Routing engine this mapping can be added using the RouteTable in Application_Start:

 

RouteTable.Routes.Add("Product",
new Route("Product/{name}",
new PageRouteHandler("~/Product.aspx")));

To add bi-directional routing support today, users would have to use URL rewriting on the query string. However, in ASP.NET 4.0 users can register expression builders:

 

<system.web>
<compilation>
<expressionBuilders ...>
<add expressionPrefix="RouteUrl"
type="System.Web.Compilation.RouteUrlExpressionBuilder" />

<add expressionPrefix="RouteValue"
type="System.Web.Compilation.RouteValueExpressionBuilder" />
</expressionBuilders>
</compilation>
</system.web>

The first expression is for getting a URL and the second for getting a value. The $ sign is used to access expressions from an aspx page:

<asp:HyperLink NavigationUrl="<%$ RouteUrl:RouteName=Product, name=Jerseys" 
Text="Jerseys"
runat="server" />

To get the value from the name attribute, users use the Route object instead of the Request object:

RouteData.Values["name"];

or using an expression builder:

<%$ RouteValue:name %>

By using ASP.NET Routing and the new bi-directional support users can decouple URLs from a physical Web Form, allowing friendlier URLs and have search engines discover and use these.


本文转自灵动生活博客园博客,原文链接:http://www.cnblogs.com/ywqu/archive/2009/03/07/1405024.html,如需转载请自行联系原作者



相关文章
|
2月前
|
开发框架 .NET C#
ASP.NET Core Blazor 路由配置和导航
大家好,我是码农刚子。本文系统介绍Blazor单页应用的路由机制,涵盖基础配置、路由参数、编程式导航及高级功能。通过@page指令定义路由,支持参数约束、可选参数与通配符捕获,结合NavigationManager实现页面跳转与参数传递,并演示用户管理、产品展示等典型场景,全面掌握Blazor路由从入门到实战的完整方案。
232 6
|
9月前
|
Shell 网络安全 C#
一款 .NET 开源、功能强大的远程连接管理工具,支持 RDP、VNC、SSH 等多种主流协议!
一款 .NET 开源、功能强大的远程连接管理工具,支持 RDP、VNC、SSH 等多种主流协议!
285 4
|
7月前
|
缓存 开发框架 .NET
一个功能丰富的 .NET 工具库 XiHan.Framework.Utils
XiHan.Framework.Utils 是一个功能全面的 .NET 工具库,包含字符串处理、集合扩展、加密解密、分布式 ID、文件操作、缓存、线程、国际化等模块。设计上注重高内聚、低耦合,适用于各类 .NET 应用开发。支持 AES 加密、树形结构转换、分页过滤、日志输出等功能,提供简单易用的 API。可通过 NuGet 快速安装,源码开放,采用 MIT 协议。
260 56
|
12月前
|
Linux API C#
基于 .NET 开发的多功能流媒体管理控制平台
基于 .NET 开发的多功能流媒体管理控制平台
198 9
|
12月前
|
网络协议 C#
3款.NET开源、功能强大的通讯调试工具,效率提升利器!
3款.NET开源、功能强大的通讯调试工具,效率提升利器!
180 10
|
12月前
|
XML C# 数据格式
一个.NET开源、免费、功能强大的 PDF 处理工具
一个.NET开源、免费、功能强大的 PDF 处理工具
358 8
|
12月前
|
监控 前端开发 API
一款基于 .NET MVC 框架开发、功能全面的MES系统
一款基于 .NET MVC 框架开发、功能全面的MES系统
338 5
|
12月前
|
开发框架 监控 .NET
C#进阶-ASP.NET WebForms调用ASMX的WebService接口
通过本文的介绍,希望您能深入理解并掌握ASP.NET WebForms中调用ASMX WebService接口的方法和技巧,并在实际项目中灵活运用这些技术,提高开发效率和应用性能。
729 5
|
消息中间件 监控 数据可视化
基于.NET开源、功能强大且灵活的工作流引擎框架
基于.NET开源、功能强大且灵活的工作流引擎框架
357 3
|
XML 开发框架 .NET
.NET 9 中 LINQ 新增功能实操
.NET 9 中 LINQ 新增功能实操
140 0

热门文章

最新文章