簡體   English   中英

帶Web表單的動態URL路由

[英]Dynamic URL Routing w/ Web Forms

我以前曾在這里張貼過,但都導致死胡同。 首先,我通過ASP 4.0和MapPageRoute使它起作用。 但在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中對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,但我無法控制它,因此需要解決。 誰想成為我的救星?

沒人不知道嗎???

使用ASP 4.0從GoDaddy切換到Web主機...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM