0
我是新來的URL路由。傳遞querystring ID使用名稱空間的URL路由system.web.Routing
案例一:我可以實現URL路由爲URL:/content/category.aspx
映射到/Reservation
案例2:我不太知道如何處理的查詢字符串值。
例如:
URL:/content/category.aspx?SID=5&CID=191
我想這映射到:案例1的書面/Reservation
代碼:
的Global.asa
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
RegisterRoutes(RouteTable.Routes)
End Sub
Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
Dim urlPattern As String
Dim Reservation As Route
urlPattern = "Reservation/"
Reservation = New Route(urlPattern, New JRouteHandler("~/content/category.aspx"))
RouteTable.Routes.Add("Reservation", New Route("Reservation", New JRouteHandler ("~/content/category.aspx")))
End Sub
的Http處理器
Public Sub New(ByVal virtualPath As String)
_virtualPath = virtualPath
End Sub
Public Function GetHttpHandler(ByVal requestContext As RequestContext) As IHttpHandler Implements IRouteHandler.GetHttpHandler
If (Not UrlAuthorizationModule.CheckUrlAccessForPrincipal(_virtualPath, requestContext.HttpContext.User, requestContext.HttpContext.Request.HttpMethod)) Then
requestContext.HttpContext.Response.StatusCode = CInt(Fix(HttpStatusCode.Unauthorized))
requestContext.HttpContext.Response.End()
End If
Dim display = TryCast(BuildManager.CreateInstanceFromVirtualPath(_virtualPath, GetType(Page)), name)
display.pageName = TryCast(requestContext.RouteData.Values("name"), String)
Return display
End Function
Public Interface name
Inherits IHttpHandler
Property pageName() As String
End Interface
- 在Web配置
</modules>
@OP,請編輯並重寫有關web配置問題的最後部分 - 完全不清楚您的問題是什麼。 – 2009-06-16 03:52:44
我用Intelligencia.UrlRewriter.dll來重寫URL.If我通過ASP.NET開發服務器運行應用程序,我可以實現我的路由(http:localhost:1130/reserve/home)如果我通過IIS 5.1運行應用程序,我mgetting HTTP 404文件未找到錯誤。 – jyoti 2009-06-30 04:00:20