Hello,
I’m using some code I got from "Code Project" and it is working for me and my co-worker. The problem is, it’s not working for one of our users becuase if is getting an "object reference is null" error on the session variable. Can anyone give me some guidance?
Code:
Public Shared Property ScreenResolution() As Size
Get
Return DirectCast(HttpContext.Current.Session("ScreenResolution"), Size)
End Get
Set(value As Size)
HttpContext.Current.Session("ScreenResolution") = value
End Set
End Property
<WebMethod()> _
Public Shared Sub setResolution(width As Integer, height As Integer)
ScreenResolution = New Size(width, height)
End Sub
<script type="text/javascript">
function getScreenResolution() {
PageMethods.setResolution(window.innerWidth, window.innerHeight);
}
</script>
”” in button click event….
ViewState("screenWidth") = ScreenResolution.Width
ViewState("screenHeight") = ScreenResolution.Height
Check if you are using Cookie based Sessions and in such case, if the user has his browser settings to disable/block Session cookies.
See this excerpt from Brian’s comments from this reference:
http://stackoverflow.com/a/1401341/3070806
It is possible to completely block the session cookie. For instance, in IE8, I just went into Tools > Internet Options > Privacy. When I cranked the slider up to ‘High’ or greater, my sites never got past the login screen because the session cookie
was blocked – in fact, Josh Stodola said below that in this case the session would never even be created on the server.
However, understand that this type of behavior effectively breaks the Internet. So unless you’re building a site targeted at conspiracy theorists, in my opinion (and the opinion of most of the largest sites in the world) there’s no need to cater to the tiny
percentage of users who don’t play by the normal rules.
For them, the Internet just isn’t going to work the way it’s supposed to.