ASP.NET MVC 使用WebForm
时间:2011-02-20 来源:安羽.
// 忽略对 WebForms 路径的路由
routes.IgnoreRoute("WebForms/{subdir}/{page}");
public class WebFormsRouteHandler:IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
// 从URL中获取subdir参数
var subdir= requestContext.RouteData.GetRequiredString("subdir");
// 从URL中获取page参数
var page = requestContext.RouteData.GetRequiredString("page");
// 创建实例
// 根据 page 参数拼接成类似/WebForms/account/page.aspx地址来访问WebForms页面
IHttpHandler hander = BuildManager.CreateInstanceFromVirtualPath("/WebForms/"+subdir+"/"+ this.page+".aspx", typeof(System.Web.UI.Page)) as IHttpHandler;
return hander;
}
}
相关阅读 更多 +