M
mews.microsoft.com
My ASP.NET pages record the referal url for each current page into session.
This is then being used by the cancel button to go back to the calling page.
Page Navigation is achieved thru' Server.Transfer always (NOT
response.Redirect)
E.g.
Search -> Initial Create Page -> Create Page
Search & Results -> Initial Create Page -> Create Page
Search & Retrieve -> Edit Page
Search & Retrieve -> Delete Page
However some of these pages may be accessed thru a third page and therefore
the need for the CancelURL to go back to the Calling Page
ISSUEs ARE:
1. When the request reached the Credit / Edit / Delete Pages (Same
Physical Page) the
Request.URL.LocalPath and
Request.ServerVariables.Item("SCRIPT_NAME")
both point to the referring page as the current page and I am
therefore unable to ascertain what the current page is to save the
URL.Referrer.
I was able to partially override the issue with the check but
even this behaves differently if the page results in handled errors. In such
cases Request.UrlReferrer if pointing to the current page
If _url Is Nothing OrElse _url.Equals(String.Empty) Then
_url = New Uri(Request.UrlReferrer.ToString).PathAndQuery
End If
Is there a setting / Parameter I am missing ?
Is this a known bug ?
Any clues / Alternatives will be greatly appreciated.
Assiciated Issue
2. URL.Referrer also does not point to the most recent URL For e.g. a
single page (Search & Search Results is the same physical Page) may call a
page from two different modes
e.g.
Search -> Initial Create Page -> Create Page
Search & Results -> Initial Create Page -> Create Page
In some cases the URL containing the Query
/SearchPage?Mode=SearchResults is not the URL.Referrer it is
/SearchPage?Mode=Search and the requirement is to go back to
/SearchPage?Mode=SearchResults
***************** Page Event (PageBase) ******************************
NOTE: I get the same results where ever I place this code (Page load, Pre
Render etc)
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
If Not IsPostBack AndAlso Not Request.UrlReferrer Is Nothing Then
CancelUrl = Request.UrlReferrer.ToString
End If
End Sub
***************** Page Property (PageBase) ******************************
Public Property CancelUrl() As String
Get
Dim _url As String
GetPropertyValue(Request.Url. , _url) ' This retrieves it from
session (db)
If _url Is Nothing OrElse _url.Equals(String.Empty) Then
_url = New Uri(Request.UrlReferrer.ToString).PathAndQuery
End If
Return _url
End Get
Set(ByVal Value As String)
If Not New Uri(Value).AbsolutePath.Equals(Request.Url.LocalPath)
Then
'only set when target is not = source
SetPropertyValue(Request.Url.LocalPath, New
Uri(Value).PathAndQuery) ' This saves it to session (db)
End If
End Set
End Property
This is then being used by the cancel button to go back to the calling page.
Page Navigation is achieved thru' Server.Transfer always (NOT
response.Redirect)
E.g.
Search -> Initial Create Page -> Create Page
Search & Results -> Initial Create Page -> Create Page
Search & Retrieve -> Edit Page
Search & Retrieve -> Delete Page
However some of these pages may be accessed thru a third page and therefore
the need for the CancelURL to go back to the Calling Page
ISSUEs ARE:
1. When the request reached the Credit / Edit / Delete Pages (Same
Physical Page) the
Request.URL.LocalPath and
Request.ServerVariables.Item("SCRIPT_NAME")
both point to the referring page as the current page and I am
therefore unable to ascertain what the current page is to save the
URL.Referrer.
I was able to partially override the issue with the check but
even this behaves differently if the page results in handled errors. In such
cases Request.UrlReferrer if pointing to the current page
If _url Is Nothing OrElse _url.Equals(String.Empty) Then
_url = New Uri(Request.UrlReferrer.ToString).PathAndQuery
End If
Is there a setting / Parameter I am missing ?
Is this a known bug ?
Any clues / Alternatives will be greatly appreciated.
Assiciated Issue
2. URL.Referrer also does not point to the most recent URL For e.g. a
single page (Search & Search Results is the same physical Page) may call a
page from two different modes
e.g.
Search -> Initial Create Page -> Create Page
Search & Results -> Initial Create Page -> Create Page
In some cases the URL containing the Query
/SearchPage?Mode=SearchResults is not the URL.Referrer it is
/SearchPage?Mode=Search and the requirement is to go back to
/SearchPage?Mode=SearchResults
***************** Page Event (PageBase) ******************************
NOTE: I get the same results where ever I place this code (Page load, Pre
Render etc)
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
If Not IsPostBack AndAlso Not Request.UrlReferrer Is Nothing Then
CancelUrl = Request.UrlReferrer.ToString
End If
End Sub
***************** Page Property (PageBase) ******************************
Public Property CancelUrl() As String
Get
Dim _url As String
GetPropertyValue(Request.Url. , _url) ' This retrieves it from
session (db)
If _url Is Nothing OrElse _url.Equals(String.Empty) Then
_url = New Uri(Request.UrlReferrer.ToString).PathAndQuery
End If
Return _url
End Get
Set(ByVal Value As String)
If Not New Uri(Value).AbsolutePath.Equals(Request.Url.LocalPath)
Then
'only set when target is not = source
SetPropertyValue(Request.Url.LocalPath, New
Uri(Value).PathAndQuery) ' This saves it to session (db)
End If
End Set
End Property