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,如需转载请自行联系原作者



相关文章
|
3月前
|
Linux API C#
基于 .NET 开发的多功能流媒体管理控制平台
基于 .NET 开发的多功能流媒体管理控制平台
69 9
|
3月前
|
XML C# 数据格式
一个.NET开源、免费、功能强大的 PDF 处理工具
一个.NET开源、免费、功能强大的 PDF 处理工具
|
3月前
|
网络协议 C#
3款.NET开源、功能强大的通讯调试工具,效率提升利器!
3款.NET开源、功能强大的通讯调试工具,效率提升利器!
72 10
|
3月前
|
监控 前端开发 API
一款基于 .NET MVC 框架开发、功能全面的MES系统
一款基于 .NET MVC 框架开发、功能全面的MES系统
|
3月前
|
开发框架 监控 .NET
C#进阶-ASP.NET WebForms调用ASMX的WebService接口
通过本文的介绍,希望您能深入理解并掌握ASP.NET WebForms中调用ASMX WebService接口的方法和技巧,并在实际项目中灵活运用这些技术,提高开发效率和应用性能。
117 5
|
4月前
|
消息中间件 监控 数据可视化
基于.NET开源、功能强大且灵活的工作流引擎框架
基于.NET开源、功能强大且灵活的工作流引擎框架
108 3
|
4月前
|
XML 开发框架 .NET
.NET 9 中 LINQ 新增功能实操
.NET 9 中 LINQ 新增功能实操
|
4月前
|
网络协议 Unix Linux
精选2款C#/.NET开源且功能强大的网络通信框架
精选2款C#/.NET开源且功能强大的网络通信框架
141 0
|
4月前
|
开发框架 JavaScript 前端开发
2024年全面且功能强大的.NET快速开发框架推荐,效率提升利器!
2024年全面且功能强大的.NET快速开发框架推荐,效率提升利器!
120 0
|
4月前
|
网络协议 网络安全 Apache
一个整合性、功能丰富的.NET网络通信框架
一个整合性、功能丰富的.NET网络通信框架

热门文章

最新文章