In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about the programming idea of ASP.NET Session failure, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
When writing a customer's MS S structure application, I suddenly found a skill. I didn't know whether it was a BUG of MS. I originally considered writing a class to check Session for relevant research friends. After the Session failed, I had to turn to the landing page, but every page that called this class was under a different Web path, so the URL to the landing page was different, and each page had to call and set the landing page path. So the practical application gave up this idea and later considered that it would be better to write a page that checks the failure of ASP.NET Session, which can be called in a page after refreshing every second by the client, but when embedding the ASPX through FRAME, there is a request issued when it is old, which is not very good-looking, although the page is hidden. Later, think about it, just use a page, use no refresh technology, to request the invalid Session page, the brushless technology here uses the XMLhttp object, not the WebService technology. Because the customer's BS system uses the FRAME framework, the top page displays the software name and user login information, so the call is placed on this page.
Let's take a look at the code, mainly the client-side JavaScript script
< script language="javascript">Var idx=0; function ChkSession () {var Http = new ActiveXObject ("Microsoft.XMLHTTP"); Http.open ("GET", "ChkSessionOut.aspx", false); / / check the page Http.send () where ASP.NET Session fails; var str = Http.responseText;// returns the result / / idx++ / / document.all ("ConvertResult") [xss_clean] = str+idx after executing ASPX If (str== "notnull") {/ / alert (str);} else {alert ("session value tracking time has expired, please log in again."); / / this code has not been running. Read on, you will know that location.href = "longin.aspx";} window.setTimeout ('ChkSession ()', 1000) / / every second, request a ChkSessionOut.aspx}
< /script>This CODE, I put it in
< HEAD> < /HEAD>Tag, and then call this function when BODY loads, as follows:
< BODY onload=ChkSession();">The code for ChkSessionOut.aspx.cs is as follows: all the HTML tags in the ChkSessionOut.aspx file are deleted by me, so that the following code is executed, and only the output of the result is left.
Private void Page_Load (object sender, System.EventArgs e) {if (Session ["sUserID"] = = null) {Response.Write ("isnull"); return;} else {Response.Write ("notnull"); return;}}
In order to test the above program, I will change the content of WEB.Config, change the SESSION setting section to part of the WEB.Config file that expires one minute later, and set the place where the SESSION expires after one minute, as follows:
< sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="1"/>Then I run the code, I specially on the original IE, use the menu to open a new IE window, to ensure that they are to check the same SESSION, enter ChkSessionOut.aspx in the address, after the program runs, found the secret, a minute later, I click to refresh the ChkSessionOut.aspx page, unexpectedly output notnull, I thought, by the way, I am sending requests to this page every second, so the reason for not invalidating Then I closed the page with or without refresh technology, and a minute later, I found that the output isnull, indicating that Session was invalid, this discovery is good, I was surprised! Think of VS.net, it is a good tool, my environment IIS5.0,Win2000,VS.Net2003 and then I have set 30 seconds automatic request, no refresh technology of the main page does not close, SESSION does not fail, a closed or 1 minute after the expiration, considering that 1 minute / 30 seconds is an integer, set to 50 seconds, no refresh technology of the main page is not closed, it passed 1 minute, invalidated. Because 1 minute / 50 seconds is not an integer, it is invalid.
This makes sense of the failure of ASP.NET Session.
After reading the above, do you have any further understanding of the programming idea of ASP.NET Session failure? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.