Session explanation, ASP. NET core knowledge (8), sessionasp.netIntroduction Session
1.FunctionCookie exists on the client, and Session exists on the server for the same purpose: save data related to the current client (any page on the current website can get the Session ).I
Introduction to ASP. NET Core middleware for Distributed Session and core Middleware
1.1. Middleware principles
1.1.1. What is middleware?
Middleware is a piece of code used to process requests and responses. Generally, multiple middleware links to form a pipeline, and each middleware determines whether to call the next middleware.
1.1.2. Middleware Execution Process
An example is provided to demonstrate t
codeThe Code is as follows: if (Request. Cookies ["uid"]! = Null){String ruid = Request. Cookies ["uid"]. Value;}
Unique Assignment Method in. NET:Copy codeThe Code is as follows: System. Web. HttpCookie user_cookies_id = new HttpCookie ("uid ");User_cookies_id.Value = "20 ";User_cookies_id.Expires = DateTime. Now. AddDays (1 );Response. AppendCookie (user_cookies_id );--------------------------------HttpCooKie acookie = new Httpcookie ("lastvisitcounter ");Acookie. value = lastvisitcounter. To
been replaced by setattribute (String attribute, Object Value)
Object getValue (String attribute)
Methods that are not recommended. has been replaced by getattribute (String attr)
Boolean isnew ()
Returns whether the session is a newly created
void Invalidate ()
Invalidate the session
The default time-out for the
Check ASP. whether the net session expires or not. The default value is 20 minutes. The setting method is session. timeout = 30; or you can set it to a higher value. The unit of the value is minute, depending on the situation.
CheckCodeWhether session. Abandon () or not. Once the abandon method is called, the current
("a.aspx");Receiving end:UserInfo UI = session["UI"] as UserInfo;Name. Text = Ui.name;Age. Text = Ui.age;Password. Text = Ui.password;Sex. Text = Ui.sex;Session time (Destruction method: Timeout and manual destruction):The default time setting for an ASP. NET session is 20 minutes, which means the server will automati
In the personnel file management system, I have a deep understanding of session and cookie usage. Next I will summarize and learn this knowledge point.What is a session?
Simply put, it is the number that the server sends to the client. When a WWW server is running, several users may browse the website running on this server. When a user establishes a connection with the WWW server for the first time, the us
mention later.
In addition to SessionID, there is a lot of additional information in each session. But for the program to write ASP or asp.net, the most useful thing is to access asp/asp. NET, which stores individual information for each user. For example, we would like to know if the users visiting our site have browsed through several pages, and we may include them in each page that the user may visit:
Microsoft and open source Dry comparison of _php and ASP. NET difference in session implementation and management mechanismPreface:Because the developer to rely on tools to eat, May and development tools, language, environment spend more time than the wife and children, so each person more or less on their own food tools in the emotional with religious complex, in the rational and the buttocks to determine
ASP. the session in net is much more flexible and powerful than the session in ASP. It is also much more complicated. See some asp. NET developers complain that the session is unstable and is lost inexplicably. In fact, this is ASP.. net
. NET Session loss solution and cause analysisDetermine whether the Session has expired:Implemented through BasePage or IHtttpMoudleBecause the Asp.net program is configured by default, the Session settings in the Web. Config file are as follows:SqlConnectionString = 'data source = 127.0.0.1; Trusted_Connection = y
other functions that we will mention later.
In addition to SessionID, a lot of other information is included in each session. However, for programs that write ASP or ASP. NET, the most useful thing is to access the asp/asp. NET has built-in session objects that store individual information for each user. For example,
In ASP. NET, the State persistence methods include applicationstate, sessionstate, Cookie, configuration file, and cache.
Typical applications of applicationstate, such as storing global data.
A typical application of sessionstate, such as saving a shopping cart project.
Typical cookie applications, such as website personalization.
Typical application of the configuration file, such as saving the customer account information.
Typical applications of
Summary of Solutions to session loss
Recently, when I was working on an ASP. NET project, the test website could not retrieve the value in the session. I searched online and found some solutions, which are recorded here. Finally, the problem is solved using the method stored in StateServer.
Sessionstate timeout). There are three main reasons:
I. Some an
write application code.
Once the application-specific information is added to session state, the server manages the object. Depending on the options you specify, you can store session information in a Cookie, in an out-of-process server, or on a computer running Microsoft SQL Server.
By default, all ASP.net applications enable ASP.net session state.
A recent study on the session failure in the. NET MVC project, the following small series to share the research process, we can refer to the next.
Recently resolved the session expiration problem based on the. NET MVC project, this conversation with you.
1. Problem analysis
In.
Because the asp tutorial. net program is the default configuration, the session settings in the web. config file are as follows:The sessionstate label has an attribute mode. It can have three values: inproc and stateserver? Sqlserver (case sensitive ). The process is unstable. When some events occur, the process restarts, causing the loss of sessions stored in the process.Under what circumstances will the p
the membership FormsAuthentication validation, then also need to Authid also follow the SessionID method, which is not mentioned in other articles about swfupload this bug processing.
Set the Post_params parameter in the SWFUpload constructor:
The code is as follows
Copy Code
SWFU = new SWFUpload ({Upload_url: "/adminht/uploadarticleimg.ashx",Post_params: {"Aspsessid": ""Authid": "},
Add the following code to the Application_BeginRequest in Global.asax:
1. Because the project DLL file changes more frequently, and save the status of the landing in the session, so that users often do not drop the line. (The session is lost due to DLL changes)2. There is a way to save the session for a long time, that is the session SQL Server mode. Let's start by introducing the four mo
, the third day is the case again, I took the last ASP. the session storage method in NET is to store the Session in SQLServer. I think the stability should be better.
To use SQLServer, run InstallSqlState on the SQL server computer in the session state. SQL or InstallPersistSqlState. default SQL location: systemroot \
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.