tcchou glad to help.
I would like to add that if you remark
[If Request.IsAuthenticated Then] at line 81
this will through an exception at
[Dim objUser As UserInfo = objUsers.GetUser(PortalId, Int32.Parse(context.User.Identity.Name))] at line 229.
This is because if the user is logged in it will apply the user address.
To resolve this I moved [If Request.IsAuthenticated Then] to line 231
So to make it simple replace the code below
// code
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
If Not Page.IsPostBack Then
valid = True
Select Case Nothing
Case Settings("street")
valid = False
Case Settings("city")
valid = False
Case Settings("region")
valid = False
Case Settings("country")
valid = False
Case Settings("postalcode")
valid = False
End Select
If valid Then
If CType(Settings("location"), String) <> "" Then
lblLocation.Text = CType(Settings("location"), String)
' RLH: rem - If Request.IsAuthenticated Then
hypDirections.Text = "Get Directions"
hypDirections.NavigateUrl = BuildDirectionsURL()
' RLH: rem - End If
If CType(Settings("showaddress"), Boolean) Then
lblAddress.Text = FormatAddress(CType(Settings("unit"), String), CType(Settings("street"), String), CType(Settings("city"), String), CType(Settings("region"), String), CType(Settings("country"), String), CType(Settings("postalcode"), String))
End If
End If
If Not CType(Settings("defaultzoom"), String) = "" Then
_zoom = CType(Settings("defaultzoom"), String)
End If
If Not CType(Settings("defaultsize"), String) = "" Then
_size = CType(Settings("defaultsize"), String)
End If
If CType(Settings("customsize"), Boolean) Then
colZoom.Visible = True
colSize.Visible = True
If Not cboZoom.Items.FindByValue(_zoom) Is Nothing Then
cboZoom.ClearSelection()
cboZoom.Items.FindByValue(_zoom).Selected = True
End If
If Not cboSize.Items.FindByValue(_size) Is Nothing Then
cboSize.ClearSelection()
cboSize.Items.FindByValue(_size).Selected = True
End If
Else
colZoom.Visible = False
colSize.Visible = False
End If
BuildMapImage()
Else
hypMap.Visible = False
hypDirections.Visible = False
colSize.Visible = False
colZoom.Visible = False
hypMapImage.BorderWidth = Unit.Pixel(0)
hypMapImage.Visible = False
If PortalSecurity.IsInRoles(PortalSettings.ActiveTab.AdministratorRoles.ToString) Then
lblAddress.Text = "Address has not been entered."
End If
End If
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
//end code
//code
Private Function GetMapImageURL(ByVal strURL As String, Optional ByVal IgnoreCache As Boolean = False) As String
Try
Dim strMapQuestURL As String = Convert.ToString(DataCache.GetCache("MapQuestURL" & ModuleId.ToString))
If (strMapQuestURL = "") OrElse IgnoreCache Then ' RLH: changed (IsNothing) to (= "")
Try
Dim objRequest As HttpWebRequest = GetExternalRequest(strURL)
Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse)
Dim sr As StreamReader
sr = New StreamReader(objResponse.GetResponseStream())
Dim strResponse As String = sr.ReadToEnd()
sr.Close()
Dim intPos1 As Integer
Dim intPos2 As Integer
intPos1 = InStr(1, strResponse, "mqmapgend")
intPos1 = InStrRev(strResponse, "http://", intPos1)
intPos2 = InStr(intPos1, strResponse, """")
strMapQuestURL = Mid(strResponse, intPos1, intPos2 - intPos1)
If Not IgnoreCache Then
DataCache.SetCache("MapQuestURL" & ModuleId.ToString, strMapQuestURL)
End If
Catch ex As Exception
' TODO: add exeption handler
End Try
End If
Return strMapQuestURL
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Function
//end code
//code
Private Function BuildDirectionsURL() As String
Try
Dim objRegionalController As New RegionalController
Dim strURL As New StringBuilder
strURL.Append("http://www.mapquest.com/directions/main.adp?go=1")
strURL.Append("&2a=" & EncodeValue(CType(Settings("street"), String)))
strURL.Append("&2c=" & EncodeValue(CType(Settings("city"), String)))
If Not Settings("country") Is Nothing Then
Select Case CType(Settings("country"), String).ToLower
Case "united states", "canada"
Dim w As String = objRegionalController.GetRegionByDescription(CType(Settings("region"), String)).Code
strURL.Append("&2s=" & EncodeValue(objRegionalController.GetRegionByDescription(CType(Settings("region"), String)).Code))
Case Else
strURL.Append("&2s=" & EncodeValue(CType(Settings("region"), String)))
End Select
' RLH: rem - hypDirections.Visible = False
End If
strURL.Append("&2y=" & EncodeValue(CType(Settings("country"), String)))
strURL.Append("&2z=" & EncodeValue(CType(Settings("postalcode"), String)))
Dim _portalSettings As PortalSettings = CType(HttpContext.Current.Items("PortalSettings"), PortalSettings)
If Request.IsAuthenticated Then ' RLH: added
Dim objUsers As New UserController
Dim objUser As UserInfo = objUsers.GetUser(PortalId, Int32.Parse(context.User.Identity.Name))
If Not objUser Is Nothing Then
strURL.Append("&1a=" & EncodeValue(objUser.Street))
strURL.Append("&1c=" & EncodeValue(objUser.City))
strURL.Append("&1s=" & EncodeValue(objUser.Region))
strURL.Append("&1y=" & EncodeValue(objUser.Country))
strURL.Append("&1z=" & EncodeValue(objUser.PostalCode))
End If
End If ' RLH: added
Return strURL.ToString
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Function
//end code