i m using same code for web,android and ios.
on login i saved value in session and localstorage..
string script = "";
script += "localStorage.setItem('Student_id','" + Student_id + "');";
script += "localStorage.setItem('Student_session','" + Student_session + "');";
script += "setTimeout(function(){ window.location='Dashboard.aspx'; }, 200);";
ClientScript.RegisterStartupScript(this.GetType(), "SaveLS", script, true);
but when session expired..i m not able to get value from local storage
protected void Page_Load(object sender, EventArgs e)
{
bool isSessionAvailable =
Session["Student_id"] != null &&
Session["Student_session"] != null;
// 🔵 Restore session if expired
if (!isSessionAvailable &&
!string.IsNullOrEmpty(hfStudentId.Value) &&
!string.IsNullOrEmpty(hfSession.Value))
{
Session["Student_id"] = hfStudentId.Value.Trim();
Session["Student_session"] = hfSession.Value.Trim();
Session["Android"] = hfAndroid.Value ?? "";
Session["Iphone"] = hfIphone.Value ?? "";
isSessionAvailable = true;
}
// 🔴 If still no session → login
if (!isSessionAvailable)
{
Response.Redirect("login.aspx", false);
Context.ApplicationInstance.CompleteRequest();
return;
}
// 🟢 STEP 3: Normal page load
if (!IsPostBack )
{
}
}
on html side
<asp:HiddenField ID="hfStudentId" runat="server" />
<asp:HiddenField ID="hfSession" runat="server" />
<asp:HiddenField ID="hfAndroid" runat="server" />
<asp:HiddenField ID="hfIphone" runat="server" />
<script type="text/javascript">
Sys.Application.add_load(function () {
var sid = localStorage.getItem("Student_id");
var sess = localStorage.getItem("Student_session");
if (sid && sess &&
document.getElementById('<%= hfStudentId.ClientID %>').value === "") {
document.getElementById('<%= hfStudentId.ClientID %>').value = sid;
document.getElementById('<%= hfSession.ClientID %>').value = sess;
document.getElementById('<%= hfAndroid.ClientID %>').value = localStorage.getItem("Android") || "";
document.getElementById('<%= hfIphone.ClientID %>').value = localStorage.getItem("Iphone") || "";
__doPostBack('', '');
}
});
</script>
pls help