开发者

Strange behaviour when using Response.Redirect and SiteMaps

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

En开发者_开发问答d 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?


Have you tried doing Response.Redirect("~/anotherPage.aspx", true) ? The true is to end processing of the current page, which it sounds like it is doing.


please check the CodeBehind file in the @Page directive in anotherPage.aspx. It should be "anotherPage.aspx.vb", looks like that is referring to "somePage.aspx.vb".


Got this sorted by the way - just in case anyone else has the same issue. I included this in the same code behind files.

' Remove the site map resolver on unload. Causes all kinds of weird issues if we don't do this.
Private Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
    RemoveHandler SiteMap.SiteMapResolve, AddressOf Me.ExpandForumPaths

End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜