I hope it will be helpful to those who encounter this problem. Below is the source code of Asp.net, which can be downloaded.
Window. Open open window session loss
Although window. Open is not flattering, it is sometimes useful. Nowadays, many office automation systems (OA ),
In order to give users a larger operation space, a window with only a title bar is opened with window. open after the user logs in.
However, in the open window, the session generated in the login window cannot be found.
I. Solutions in Asp.net:
1: If the logon window is default. aspx, we can write it in the background as follows:
1 string user = request. Form ["user"];
2 session ["_ uid"] = user;
3 string SID = session. sessionid;
4 page. registerstartupscript
5 ("open", "<SCRIPT>
6 window. Open
7 ('index. aspx? SID = "+ Sid +" ',' _ blank ', 'status = Yes, scrollbars = Yes, resizable = Yes ');
8 </SCRIPT> ");
9
In this way, we can pass the sessionid to the newly opened window index. aspx. In index. aspx, we can
Reconstructs a session.
2: In index. aspx, we can reconstruct the session as follows:
1 using system. Web. sessionstate;
2
3 Public partial class index: system. Web. UI. Page
4 {
5 protected void page_load (Object sender, eventargs E)
6 {
7 string SID = request. querystring ["Sid"]. tostring ();
8 sessionidtest Ss = new sessionidtest (SID );
9 ss. createsessionid (context );
10}
11}
12
13 public class sessionidtest: sessionidmanager
14 {
15 private string Sid;
16 public sessionidtest (string Sid)
17 {
18 this. Sid = Sid;
19}
20 public override string createsessionid (httpcontext context)
21 {
22 return Sid;
23}
24
25}
Here, we use the sessionidmanager class in the sessionstate namespace. We rewrite its createsessionid
This virtual method re-obtains the session. The createsessionid virtual method needs to be rewritten. It returns a new session.
The sessionid of the newly constructed
The session in the session and login window is a session.
Ii. Solutions in PHP:
1: solve this sesssion loss in PHP. The same method is used, and it is simpler. You only need two functions,
Session_start ();
$ SID = session_id ();
The session_id function is used to obtain the sessionid of the logon interface.
2: Then we can construct a session based on the sessionid like in. Net:
$ SID = $ _ Get ['sid '];
Session_id ($ Sid );
Session_start ();
The session_id function re-constructs the session.