I have an MVC application which sets some session variables based on internal static IP addresses.
I have built an ApplicationController to override the OnActionExecuted sub in MVC for data that I need to use throughout my application.
However, the code below, which is just a snippet of my code but is edited for my post, only partially works. On initial page load, the session variables aren't saved, but after a page refresh they are. The issue I have is that these need to be saved on the initial page load.
If Session("Item1") = Nothing Then
If IpAddressShort <> "" Then
Dim locInfo = cmsRepository.GetInfoBasedOnLocation(IpAddressShort).SingleOrDefault()
If locInfo IsNot Nothing Then
Session("Item1") = locInfo.Item1
Session("Item2") = locInfo.Item2
Session("Item3") = locInfo.Item3
Session("Item4") = locInfo.Item4
If locInfo.Item2= "1" Then
Session("Visibility") = 3
Session("TypeShort") = "XXXX"
ElseIf locInfo.Item2= "2" Then
Session("Visibility") = 4
Session("TypeShort") = "YYYY"
ElseIf locInfo.Item2= "9" Then
Session("Visibility") = 2
Session("TypeShort") = "ZZZZZ"
End If
End If
End If
End If
Theoretically, if I'm correct, if there is no Session("Item1") set/if Session("Item1") is empty, then the rest of the snippet should run and set those variables.
How come this isn't setting those variables on the first time the page load?
Thanks for any help in advance