0

好的......让 URL 路由工作得很好,但无法弄清楚如何实际读取目标页面中的值。

此处的一个示例显示了使用 RequestContext 中的 RouteValue 对象。现在所有这些都在 System.Web.Routing 命名空间中,但每个人似乎都只是将它们连接到 MVC。RequestContext 来自哪里?

我如何读取这些参数???

查询字符串也是空白的。

蒂亚!凯文

4

1 回答 1

0

我自己解决了这个问题......耶!:)

开始乱搞,看到 IHttpHandler 接口为 GetHttpHandler 方法提供了 RequestContext。

所以,我修改了我的基页面类(我总是在 System.Web.UI.Page 和我自己的页面之间放置一个层,为此目的将其称为 BasePage 或类似名称)。所以我在 PVBasePage 上添加了一个公共属性来接收一个 RequestContext 对象。

public RequestContext RequestContext { get; set; }

然后,我的路由类代码如下:

IHttpHandler IRouteHandler.GetHttpHandler(RequestContext requestContext)
{
    // create the page object as my own page...
    var page = BuildManager.CreateInstanceFromVirtualPath(VirtualPath
        , typeof(PVBasePage)) as PVBasePage;
    // pass in the request context
    page.RequestContext = requestContext;
    // return this page in the form of a IHttpHandler
    return page as IHttpHandler;
}

因此,我没有像示例代码中那样直接将实例创建为 IHttpHandler,而是将其创建为我自己的页面。设置请求上下文属性,然后将页面作为 IHttpHandler 返回给调用者。

经过测试,它可以工作。呜呼!

希望这可以帮助其他人。

于 2009-03-17T03:39:02.893 回答