title: Dynamic URL Routing w/ Web Forms
body: <p>I have posted in here before but all have led to dead ends. First of all I got this to work via ASP 4.0 with MapPageRoute. But in 3.5 I apparently don't have that option.</p>
  
  <p>I want to accomplish the following:</p>
  
  <p>destination.aspx?id=1 -> destinations/rome</p>
  
  <p>destination.aspx?id=5 -> destinations/florida</p>
  
  <p>Below is the code I currently have:</p>
  
  <pre><code>&lt;%@ Import Namespace="System.Web.Routing" %&gt;
  &lt;script runat="server"&gt;
  
      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")));
      }
  </code></pre>
  
  <p>I have the necessary items in my web.config and this is whats in my webform for destination.aspx.cs:</p>
  
  <pre><code>string destinationName = Page.Request.QueryString["dest"];
  </code></pre>
  
  <p>Here is my CustomRoute.cs:</p>
  
  <pre><code>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;
      }
  }
  </code></pre>
  
  <p>and....this is the error i'm receiving:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>I wish GoDaddy would allow ASP 4.0 but I can't control that and therefore need a work around. Who wants to be my savior?</p>
  
  <p>Nobody hasn't any idea???</p>