开发者

Dynamic URL Routing w/ Web Forms

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.

I want to accomplish the following:

destination.aspx?id=1 -> destinations/rome

destination.aspx?id=5 -> destinations/florida

Below is the code I currently have:

<%@ 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")));
    }

I have the necessary items in my web.config and this is whats in my webform for destination.aspx.cs:

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

Here is my CustomRoute.cs:

pu开发者_高级运维blic 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;
    }
}

and....this is the error i'm receiving:

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;

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?

Nobody hasn't any idea???


Switch from GoDaddy to a web host with ASP 4.0...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜