My ASP.NET (VB.NET) application uses SiteMaps to display a navigation menu on the top of each page. In the code behind of some of the pages, I am dynamically amending the URLs of the SiteMaps nodes (to add parameters to the end of the URL) e.g. say I have somePage.aspx.vb and anotherPage.aspx.vb and they both contain the following:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
AddHandler SiteMap.SiteMapResolve, AddressOf Me.ExpandForumPaths
If Not Page.IsPostBack Then
Setup()
End If
End Sub
Private Function ExpandForumPaths(ByVal sender As Object, ByVal e As SiteMapResolveEventArgs) As SiteMapNode
Dim currentNode As SiteMapNode = Nothing
Try
currentNode = SiteMap.CurrentNode.Clone(True)
' Do some stuff
Catch ex As Exception
' Do nothing - don't want app falling over because of issue with nav menu
End Try
Return currentNode
End Function
My problem is this, if I am in the code behind of somePage.aspx and I do a Response.Redirect(“~/anotherPage.aspx”) – then, when anotherPage.aspx.vb is being loaded, it is the ExpandFormumPaths method of somePage.aspx.vb that is hit, not that of anotherPage.aspx.vb.
My understanding is that a Response.Redirect tells the browser to do a new request to the supplied URL – I don’t know why it’s hitting the method belonging to the previous page.
I’ve tried amending the method names (i.e. not having the node processing method called ExpandFormumPaths in all classes) but I still encountered the same issue.
When I go straight to the URL of anotherPage.aspx the correct method is hit, it is only when I am using Response.Redirect that this happens.
Any ideas?
Got this sorted by the way – just in case anyone else has the same issue. I included this in the same code behind files.