|
I'm experimenting with the httpModule, using XP and IIS5.1, asp.net 4.0, in which I want to take a file called display.aspx?pNp=XXXX and turn it into a file name XXXX.aspx.
So I wrote the first part, I know what context.Items("originalUrl") is for, but I'm not sure if I actually need it, because I don't don't have the second part written or working yet. It's been awhile since my last 3 failures at attempting this.
I'd like to get another set of eyes on my code, before I procede, in case I really blew it here. And see if there are any mistakes.
It seems to work, and I get the error message below, so I figure it's ok.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /EN-US/part-lookup/catagory/XXXX.aspx
Imports Microsoft.VisualBasic
Public Class http_module_Details
Implements IHttpModule
Public Sub Init(context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
AddHandler context.BeginRequest, AddressOf context_BeginRequest
AddHandler context.PreRequestHandlerExecute, AddressOf context_PreRequestHandlerExecute
AddHandler context.EndRequest, AddressOf context_EndRequest
End Sub
Private Sub context_PreRequestHandlerExecute(ByVal sender As Object, ByVal e As EventArgs)
Dim application As HttpApplication = DirectCast(sender, HttpApplication)
Dim context As HttpContext = application.Context
If Not context.Items("originalUrl") Is Nothing Then
context.RewritePath(Convert.ToString(context.Items("originalUrl")))
End If
End Sub
Private Sub context_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Dim application As HttpApplication = DirectCast(sender, HttpApplication)
Dim context As HttpContext = application.Context
If (context.Request.RawUrl.ToLower.Contains("details.aspx")) Then
context.Items("originalUrl") = context.Request.RawUrl
End If
Dim originalPath As String = context.Request.Url.ToString()
If Not context.Request.QueryString("pNp") Is Nothing Then
Dim cP As String = context.Request.ServerVariables("SCRIPT_NAME")
cP = cP.Replace("Details.aspx", "").Replace("details.aspx", "")
Dim pn_P As String = HttpUtility.UrlDecode(context.Request.QueryString("pNp"))
Dim scriptName As String = cP & pn_P & ".aspx"
context.RewritePath(scriptName)
End If
End Sub
Private Sub context_EndRequest(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
End Sub
End Class
|
|
|
|