The following is a summary of some Session issues, hoping to help you: Original article: http://blog.csdn.net/cuike519/archive/2005/09/27/490316.aspx
Q: Why is the Session occasionally lost on some machines? A: It may be related to the machine environment, such as firewall or anti-virus software. Try to disable the firewall.Q: Why didn't the Session_End method be activated when Session. Abandon is called? A: The Session_End method only supports sessions of the InProc (in-process) type. Second, to stimulate the Session_End method, there must be a Session (that is, the Session has been used in the system), and at least one request must be completed (this method will be called in this request ). Q: Why is Session frequently lost in InProc mode? A: This problem is usually caused by application recycling. When an in-process Session is used, the Session is saved in the aspnet_wp process, when the process is recycled, the Session will naturally disappear. To determine whether the process is recycled, you can obtain information by viewing the System Event Viewer. For more information, see: Session variables are lost intermittently in ASP. NET applicationshttp: // support.microsoft.com/default.aspx? Scid = kb; en-us; q2017148 At 1.0, a bug also causes the worker process to be recycled and restarted. The bug has been fixed in 1.1 and sp2. For more information about this bug, see: ASP. NET Worker Process (Aspnet_wp.exe) Is Recycled Unexpectedly. http://support.microsoft.com/default.aspx? Scid = kb; en-us; Q321792 Q: Why is the new Session ID the same as the original one after the Session times out or Abandoned? A: Because SessionID is saved in the client browser instance, when the Session times out and the server re-creates the Session, the Session ID sent from the browser will be used. When the Session times out, then, the SessionID remains unchanged. Q: Why are the sessionids of each request different? A: This problem may be caused by not saving any information in the Session, that is, the Session is not used anywhere in the program. After the Session information is saved, the SessionID will always be related to the browser. At this time, the SessionID will not change. Q: Can sessions be shared between ASP and ASP. NET? A: Yes. But this is a relatively complex process, Microsoft provides an official solution, please refer to: http://msdn.microsoft.com/library/default.asp? Url =/library/en-us/dnaspp/html/ConvertToASPNET. asp Q: What types of objects can be stored in the Session? A: This depends on the Session mode. When using an InProc Session, you can easily save any object. If you use the non-InProc mode, you can only save the objects that can be serialized and deserialized. If the stored objects do not support serialization, they cannot be saved to this mode (non-InProc). Q: Why can't I use the Response. Redirect and Server. Transfer methods to jump to the page in Session_End? A: Session_End is an event processing function that is triggered inside the server. It is based on the Internal timer of a Server. When the event is triggered, there is no related HttpRequest object on the Server. Therefore, the Response. Redirect and Server. Transfer methods cannot be used at this time. Q: Can I obtain the HttpContext object in Session_End? A: No, because this event is not associated with any Request and is not based on the Request context. Q: How do I use Session in Web Service? A: To use a Session in a Web Service, you need to do some additional work on the Web Service caller. You must save and store the cookies used to call the Web Service. For more information, see the HttpWebClientProtocol. CookieContainer attribute in the MSDN document. However, if you use a proxy server to access the Web Service due to framework restrictions, the two cannot share sessions. Q: Why can't I use a Session when customizing my HttpHandler? A: When implementing your own HttpHandler, if you want to use the Session, you must implement one of the following two Mark interfaces: IRequiresSessionState and IReadOnlySessionState. These interfaces do not have any implementation methods, the method for marking an interface is the same as that for using the INamingContainer interface. Q: When I use webfarm, why is the Session lost when I redirect to another Web server? A: For more information, see: PRB: Session State Is Lost in Web Farm If You Use SqlServer or StateServer Session Modehttp: // support.microsoft.com/default.aspx? Scid = kb; en-us; 325056 Q: Why is my Session invalid in the Application_OnAcquireRequestState method? A: The Session is valid only when the HttpApplication. AcquireRequestState event is called. For more information, see: http://msdn.microsoft.com/library/default.asp? Url =/library/en-us/cpguide/html/cpconhandlingpublicevents. asp Q: If cookieless is used, how can I redirect an HTTP page to HTTPS? A: try the following method: String originalUrl = "/fxtest3/sub/foo2.aspx "; String modifiedUrl = "https: // localhost" + Response. ApplyAppPathModifier (originalUrl ); Response. Redirect (modifiedUrl ); Q: Are sessions valid in global. asax events? A: The Session is valid only after the AcquireRequestState event. All events after the event can use the Session. Q: How do I obtain all objects saved in the current Session? A: You can retrieve all Session. Keys. The Code is as follows: ArrayList sessionCollection = new ArrayList (); Foreach (string strKey in Session. Keys ){ SessionCollection. Add (Session [strKey]); } Q: Can I share sessions in different applications? A: You cannot share data directly. You can refer to how to share a Session between ASP and ASP. NET. Q: What is the difference between Session. Abandon and Session. Clear? A: The main difference is that when Session. Abandon is used, the Session_End method is called (in InProc mode ). The Session_Start method is triggered when the next request arrives. Session. Clear only clears all data in the Session and does not stop the Session. Therefore, it does not call those methods. Q: Does the Session provide a locking mechanism to allow sequential access to Session Status values? A: The Session implements the Reader/Writer lock mechanism: When the Page has a writable function for the Session (that is, the Page has a <% @ Page EnableSessionState = "True" %> flag), the Session of the Page holds a write lock until the request completes. When the Page has the read-only function for the Session (that is, the Page is marked with <% @ Page EnableSessionState = "ReadOnly" %>), the Session of the Page is read locked. A read lock will block a write lock; A read lock will not block a read lock; A write lock will block all read/write locks. This is why when the same page in the two frameworks writes the same Session, one of them starts to write after the other (the one that is a little faster) completes. Q: What does Session smooth timeout mean? A: The Session smooth timeout means that as long as you access (use) The Session, the timeout will be refreshed (which can be understood as re-timing), that is, starting from the page request, the timeout value is recalculated. However, the Session cannot be disabled on this page. It will automatically access the Session on the current page and refresh the timeout time. Q: Why is the Session invalid in the event handler function in global. asax? A: It depends on the event processing function in which the Session is used. The Session is valid only after the AcquireRequestState event. All event processing functions after the event can use the Session, but not the previous one. Q: Why can't I directly use session ["key"] to obtain the value of a session that depends on the current application? A: session ["key"] is actually this. session ["key"], which is provided as an attribute of page, so you cannot directly use this attribute in your component. You can use session in the following ways: Httpcontext. Current. session ["key"] = "My seesion value "; Q: When I use inproc mode to save a session, where is the session stored? A: Different IIS processing methods are different, When iis5's session is used, the session is stored in the process space of aspnet_wp.exe. When iis6is used, all application sharing application pools are in bad condition, and sessionis stored in the w3wp.exe process space. Q: Is the Session Timeout set in minutes or seconds? A: It is minute. The default value is 20 minutes. Q: Will my session be saved when an error occurs on the page? I need to handle some cleanup work in session_end, but it fails. Why? A: session_end is executed only when the session runs in inproc mode. Session_end is the account that runs the aspnet_wp workflow (this can be set in machine. config ). Therefore, if you use the Integrated Security link to SQL in the session_end method, it will use the account of the aspnet_wp process to open the link. At this time, success and otherwise depend on your SQL security settings. Q: Why is the session lost when I set cookieless to true? A: When cookieless is used, you must replace the absolute path in the program with the relative path. If ASP. NET is used, sessionid cannot be saved in the URL. For example, replace myDirmySubdirdefault. aspx with .. default. aspx. Q: How can I store SortedList in the Session or Cache? A: refer to the following method: SortedList x = new SortedList (); X. Add ("Key1", "ValueA "); X. Add ("Key2", "ValueB "); Save to Session: Session ["SortedList1"] = x; You can use the following method to obtain it: SortedList y = (SortedList) Session ["SortedList1"]; The same applies to Chahe. Q: Why do I get the error message "Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive ve "? A: This problem may occur after Windows Sharepoint Server (WSS) is installed on a machine that has the Microsoft Visual Studio. NET development environment installed. The wss isapi filter processes all requests. When you browse an ASP. NET application through a virtual directory, the ISAPI filter does not assign a URL to the folder directory. Solution: Do not use Session on the machine where WSS is installed. For more information, see: Session state cannot be used in ASP. NET with Windows SharePoint Serviceshttp: // support.microsoft.com/default.aspx? Scid = kb; en-us; 837376 Q: How do I delete Session variables? A: You can use the HttpSessionState. Remove () method to delete the Session variable. Q: Is there a way to know how much memory the application Session occupies during running? A: No. At present, this value cannot be verified. At least I have not yet seen this information. However, you can estimate a value through the performance monitor and program code. Q: If frameset is specified on the page, the SessionID of the page displayed in each frame is different in the first request. Why? A: The reason is that your frameset is placed on an htm page instead of An ASPX page. In general, if the frameset Is An aspx page, When you request a page, it first sends the request to the Web server. At this time, the SessionID is obtained, then the browser requests other pages in the Frame respectively, so that the sessionids of all pages are the same, that is, the SessionID of the FrameSet page. However, if you use an Html page as a FrameSet page, the first request will be an HTML page. When the page is returned from the server, no Session is generated, then the browser will request the pages in the Frame, so these pages will generate their own SessionID, so this problem will occur in this case. When you refresh the page, SessionID will be the same, and it is the SessionID of the last request page. Q: Can sessions of different applications be stored in different databases on the same SQL Server. A: Yes. See: Fix: using one SQL database for all applications for SQL Server session state may cause a bottleneckhttp: // support.microsoft.com/default.aspx? SCID = KB; en-US; 836680 Q: Can I obtain valid httpsessionstate and httpcontext objects in session_end? A: You can obtain the httpsessionstate object in this method. You can directly use session to access the object. However, the httpcontext object cannot be obtained because the event is not associated with any request, so there is no context object. Q: Why does my session not expire when I use session in sqlserver mode? A: In sqlserver mode, session expiration is completed through SQL Agent Registration. Check whether your SQL Agent is running? Q: After I set enablesessionstate to "readonly", I can still modify the session value in inproc mode. Why? A: even if the enablesessionstate is set to readonly, You can edit the session in inproc mode. The only difference is that the session will not be locked during the request process. Q: How can I avoid specifying a password when connecting SQL statements? A: Use a trusted link or encrypted link string. For more information, see: How to Use the ASP. Net utility to encrypt credentials and session State connection strings http://support.microsoft.com/default.aspx? SCID = KB; en-US; 329290 Q: How can I use Session in my own class? A: You can use HttpContext. Current. Session as follows: HttpContext. Current. Session ["SessionKey"] = "SessionValue "; Similarly, you can use the Application object in this way. Q: Why is my request suspended after I switch to SQLServer mode? A: Check whether all objects saved in the Session are objects that can be saved in SQLServer mode. That is, these objects must support serialization. Q: What will happen when the Session is set to cookieless? A: When cookieless is set to true, the following constraints are imposed: 1. You cannot use absolute links on the page. 2. Some other steps are required in addition to switching between Http and Https in the application. If you send a link to another user, the URL contains the Session ID information, so the two users share a Session. Q: Can I save the Session in the database? A: Of course. For more information, see: http://support.microsoft.com/default.aspx? Scid = kb; en-us; 311209 this article is from the 51CTO. COM technical blog |