Can you provide a complete sample that can reproduce this issue so that we can help fix it?
In addition, you can also try Session.Clear() or Session.Abandon() rather than set it to null, please refer to
this thread.
PS. I changed
Server.Transfer to
Response.Redirect since Server.Transfer won't change the address bar which means when you click the button, it posts back and load current page again, this causes you need to click the logout button twice to transfer to next page. And, use
the Server.Transfer cannot reproduce this issue too.
Member
1 Points
2 Posts
After set session null comes active
May 16, 2020 12:03 AM|amoniz|LINK
Hi,
i have a login page where, i set the session data from a database
and a button for logout in a masterpage where i set
this works perfect, redirects to login page, but if i press go back button, the page is accessible with the last session that i previous set null.
I test this without master being page and works.
Regards
Contributor
3140 Points
983 Posts
Re: After set session null comes active
May 18, 2020 05:55 AM|Yang Shen|LINK
Hi amoniz,
Sorry to tell that this issue cannot be reproduced on my side.
Below is the demo i built to test the process:
FromPage.aspx:
FromPage.aspx.cs:
ChildToPage.aspx:
ChildToPage.aspx.cs:
Site.Master:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WebFormDemo02.SiteMaster" %> <!DOCTYPE html> <html lang="en"> <head runat="server"> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title><%: Page.Title %> - My ASP.NET Application</title> <asp:PlaceHolder runat="server"> <%: Scripts.Render("~/bundles/modernizr") %> </asp:PlaceHolder> <webopt:bundlereference runat="server" path="~/Content/css" /> <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> </head> <body> <form runat="server"> <asp:ScriptManager runat="server"> <Scripts> <%--To learn more about bundling scripts in ScriptManager see https://go.microsoft.com/fwlink/?LinkID=301884 --%> <%--Framework Scripts--%> <asp:ScriptReference Name="MsAjaxBundle" /> <asp:ScriptReference Name="jquery" /> <asp:ScriptReference Name="bootstrap" /> <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" /> <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" /> <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" /> <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" /> <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" /> <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" /> <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" /> <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" /> <asp:ScriptReference Name="WebFormsBundle" /> <%--Site Scripts--%> </Scripts> </asp:ScriptManager> <div class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" runat="server" href="~/">Application name</a> </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li><a runat="server" href="~/">Home</a></li> <li><a runat="server" href="~/About">About</a></li> <li><a runat="server" href="~/Contact">Contact</a></li> </ul> </div> </div> </div> <div class="container body-content"> <asp:Button ID="Button1" runat="server" Text="OUT" OnClick="Button1_Click" /> <asp:ContentPlaceHolder ID="MainContent" runat="server"> </asp:ContentPlaceHolder> <hr /> <footer> <p>© <%: DateTime.Now.Year %> - My ASP.NET Application</p> </footer> </div> </form> </body> </html>
Site.Master.cs:
Below is the result of this demo:
As you can see, the session is cleared to null.
Can you provide a complete sample that can reproduce this issue so that we can help fix it?
In addition, you can also try
Session.Clear()
orSession.Abandon()
rather than set it to null, please refer to this thread.PS. I changed Server.Transfer to Response.Redirect since
Server.Transfer
won't change the address bar which means when you click the button, it posts back and load current page again, this causes you need to click the logout button twice to transfer to next page. And, use theServer.Transfer
cannot reproduce this issue too.Best Regard,
Yang Shen
Member
1 Points
2 Posts
Re: After set session null comes active
May 21, 2020 10:07 PM|amoniz|LINK
Hi, Yang Shen
I test your solucion and it's perfect. The problem was resolved by change as you sugered:
to
Soo, I must say to you a BIG THANK YOU for the help and your time.
Regards,