简体   繁体   中英

Session lost when navigate to a new page via HTTP

I have HTML anchor tag as a button in my page. In page load I set the URL to the href property of that anchor tag. Before setting the href property, I save some information in an object and save that object in a session. That information is used in the new page that navigates after clicking that anchor tag.

When I navigate to the new page from clicking that particular anchor tag via HTTPS the session variable that I have set is persists. I can access the properties of the object that I set to that particular session.

But I navigate to the new page from clicking that particular anchor tag via HTTP, the properties of the object that I save in the session is lost. Can anyone have idea about what's going on? Why the session variables get lots when navigating to a new page via HTTP?

i think you should write code like in aspx.cs page if(!Ispostback) {session["variable"] = value; Response.Redirect("nextpage.aspx"); } if(!Ispostback) {session["variable"] = value; Response.Redirect("nextpage.aspx"); } if(!Ispostback) {session["variable"] = value; Response.Redirect("nextpage.aspx"); } after that nevigate to another page

Yes you can use LinkButton instead of anchor tag and write the code on it's event somthing like this:

protected void LinkButton_Click(object sender, EventArgs e)
    {
Session["variable"] = yourobject; 
Response.Redirect("nextpage.aspx"); 

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM