I would like to redirect users to a custom page if their session has expired.
On PageLoad
If Session("OrgID") = Nothing Then
Response.Redirect("SchoolLogin.aspx?schoolID="+[schoolid])
End If
I can store the schoolID in a hidden field on every page, but this doesn’t seem very elegant. I thought to try using the hidden field in a user control that I do have on every page, but the user control PageLoad fires after the main PageLoad so I’d get an error prior to checking for session expiration. Is there a common solution for this?
You can use QueryString, ViewState (ASP.NET’S built in hidden field) or setting it as a cookie value.
I don’t know enough about your scenario. The best I can offer is an example of how I deal with (what I am guessing) is similar to your situation.
Create a base class for all your page classes to inherit from (more here oldy but goody https://web.archive.org/web/20211020133935/https://www.4guysfromrolla.com/articles/041305-1.aspx), Add your SchoolId property to it. This is in c# I appologise, unfortunately VB.NET syntax literally makes my teeth jangle. It shouldn’t be too hard to translate though as this is pretty basic stuff.
Using QuertString, you would need to test for -1 and redirect in that case.
Using ViewState
Using cookies (More here) http://msdn.microsoft.com/en-us/library/aa289495(v=vs.71).aspx