使用/ Web窗体进行动态URL路由

时间:2010-07-15 22:19:28

标签: c# asp.net url-routing

我之前在这里发过帖,但都导致死路一条。首先,我通过带有MapPageRoute的ASP 4.0来实现这一点。但在3.5我显然没有这个选择。

我想完成以下任务:

destination.aspx?id = 1 - >目的地/罗马

destination.aspx?id = 5 - >目的地/佛罗里达

以下是我目前的代码:

<%@ Import Namespace="System.Web.Routing" %>
<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        RegisterRoutes(RouteTable.Routes);
    }
    public static void RegisterRoutes(RouteCollection routes)
    {

        RouteTable.Routes.Add(new Route("destinations/{dest}", new CustomRouteHandler("~/Destination.aspx")));
    }

我的web.config中有必要的项目,这是我的webform for destination.aspx.cs中的内容:

string destinationName = Page.Request.QueryString["dest"];

这是我的CustomRoute.cs:

public class CustomRouteHandler : IRouteHandler
{
    public CustomRouteHandler(string virtualPath)
    {
        this.VirtualPath = virtualPath;
    }

    public string VirtualPath { get; private set; }

    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        string queryString = "?id=" + requestContext.RouteData.Values["dest"];
        HttpContext.Current.RewritePath(
          string.Concat(
          VirtualPath,
          queryString));

        var page = BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof(WebPageTraceListener)) as IHttpHandler;
        return page;
    }
}

和....这是我收到的错误:

Type 'ASP.destination_aspx' does not inherit from 'System.Web.WebPageTraceListener'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: Type 'ASP.destination_aspx' does not inherit from 'System.Web.WebPageTraceListener'.

Line 26: var page = BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof(WebPageTraceListener)) as IHttpHandler;

我希望GoDaddy允许ASP 4.0,但我无法控制它,因此需要一个解决方法。谁想成为我的救世主?

没有人不知道???

1 个答案:

答案 0 :(得分:0)

从GoDaddy切换到使用ASP 4.0的网络主机...