r3plica
Well-known member
- Joined
- Mar 4, 2010
- Messages
- 86
- Programming Experience
- 3-5
Good morning all,
I have run into this problem a few times and it is quite frankly driving me nuts.
First I will paste my source code and then I will talk about my issue a little.
First of all, I have the references needed in my web.config and my URL rewriting works, but it is not stable.
What I have found is that because HttpModule is fired mulitple times on a sinlge page it runs the section below everytime.
The collections are retrieved from a database.
What happens is that the requests happen so fast, so sometimes the connection is still opening when the second request comes through, or it moans stating that it can't find column one, etc. The result is my page comes back with an error and the page isnt displayed.
I need to somehow either make "CheckURL" run only once per page request regardless of the objects on that page OR find a way to store the collections in memory (like sessions, except I realise I can't use sessions here).
Please please please help me or point me in the right direction.
If there is anything I have missed, please let me know.
I have run into this problem a few times and it is quite frankly driving me nuts.
First I will paste my source code and then I will talk about my issue a little.
VB.NET:
Imports Microsoft.VisualBasic
Imports HoN.Common
Imports HoN.Business.ItemBusiness
Imports HoN.Business.ModificationBusiness
Public Class UrlRewrite
Implements IHttpModule
Public Sub Dispose() Implements IHttpModule.Dispose
End Sub
Public Sub Init(ByVal context As HttpApplication) Implements IHttpModule.Init
AddHandler context.AuthorizeRequest, AddressOf OnAuthorizeRequest
End Sub
Private Sub OnAuthorizeRequest(ByVal s As Object, ByVal e As EventArgs)
CheckURL(CType(s, HttpApplication))
End Sub
Private Sub CheckURL(ByVal app As HttpApplication)
Dim pLocationCol As LocationCollection = ReturnItemLocations()
Dim pItemCol As ItemCollection = ReturnAllItems()
Dim pModCol As ModificationCollection = ReturnAllModifications()
For Each pLocation As Location In pLocationCol
If app.Request.RawUrl.ToLower.Contains("/items/" & Replace(Replace(pLocation.Name.ToLower, " ", ""), "'", "") & ".aspx") Then
app.Context.RewritePath("~/Results.aspx", "", "i=" & pLocation.ID)
End If
Next
For Each pItem As Item In pItemCol
If app.Request.RawUrl.ToLower.Contains("/item/" & Replace(Replace(pItem.Name.ToLower, " ", ""), "'", "")) Then
app.Context.RewritePath("~/Item.aspx", "", "i=" & pItem.ID)
End If
Next
For Each pMod As Modification In pModCol
If app.Request.RawUrl.ToLower.Contains("/mods/" & Replace(Replace(pMod.Name.ToLower, " ", ""), "'", "")) Then
app.Context.RewritePath("~/Modification.aspx", "", "i=" & pMod.ID)
End If
Next
End Sub
End Class
First of all, I have the references needed in my web.config and my URL rewriting works, but it is not stable.
What I have found is that because HttpModule is fired mulitple times on a sinlge page it runs the section below everytime.
The collections are retrieved from a database.
VB.NET:
Dim pLocationCol As LocationCollection = ReturnItemLocations()
Dim pItemCol As ItemCollection = ReturnAllItems()
Dim pModCol As ModificationCollection = ReturnAllModifications()
What happens is that the requests happen so fast, so sometimes the connection is still opening when the second request comes through, or it moans stating that it can't find column one, etc. The result is my page comes back with an error and the page isnt displayed.
I need to somehow either make "CheckURL" run only once per page request regardless of the objects on that page OR find a way to store the collections in memory (like sessions, except I realise I can't use sessions here).
Please please please help me or point me in the right direction.
If there is anything I have missed, please let me know.