A Set upCookiesof the2Kind of way
1. repsonse.cookie["name"] = value ;
2. HttpCookie Hccookie = new HttpCookie ("name", value );
Hccookie.expires = Date.Now.AddDays (1); Here you can add a month
RESPONSE.COOKIES.ADD (Hccookie);
To take a value from a Cookie :
String str = response.cookies["name"]. Value;
Attention:
1.Cookie If no time is specified, the default is until the browser is closed, and set to MaxValue means that it never expires .
2. In addition , only the string in the Cookie , i.e. response.cookie["Quantity"] = 15; is wrong, only "15".
Two How to acceptURLMedium Parameter
request.querystring["URL parameter after variable name "];
request.form["URL parameter after name "]
There is no forwarding function in C # similar to JAVA , it is impossible to pass objects, you can only put objects in the session , or viewstate page status in hold
ThreeASPthe life cycle of a page:
A. Initialization
B. Loading instance:postback--viewstate--<%@ page ...%>// This can only occur once per page
C. server Control Validation
D. Control Events
E.render Rendering Display
F. Uninstall
Generally some sensitive data: User name, password, permissions, etc. exist in the session , and the user last login time is stored in the cookie
FourSessionrelated
Get sessionId:Session.SessionID
∵SessionID are stored in cookies and cookies can be disabled.
∴ can be used:URL rewriting technology to attach SessionID to the URL , using the form-hiding technology, the server will SessionID are added to the form as hidden fields.
1.Session Syntax:
session["name"] = value ;// Note there is no value attribute, which differs from Cookie
2. Get:
Variable = session["name"];
3. Features:
Once the session expires, theServer immediately clears the session object, freeing up the occupied resources
4. Properties:
Timeout: Sets the time-out period, units: minutes;
5. Method:
Clear (): Clears all keys and values from the session-state collection (empties the value, reserving space in memory)
Abandon (): Ends session, cancels the current session (security Exit Function), because the priority is low, after the current page execution is completed before the execution, which is why the "Safe exit" button click on the page will jump.
F.session Some of the settings in the configuration file:
<system.web>
<sessionstate timeout= "" cookieless= "true" mode= "SQL Server" ></sessionState>
</system.web>
objects can be stored in 6.Session:
User user = new user ();
User.ID = 1;
UserName = "Tom";
session["UserInfo"] = user;
Can be judged based on whether the session knows NULL ---> for access control
if (session["UserInfo"]==null)
{
Response.Redirect ("index.aspx");
}
Else
{
If (! Page.IsPostBack)
{
//... welcome speech, etc.
}
Read the object in session:User user = session["UserInfo"] as User;
FiveApplicationrelated
Assignment value:
application[" name "] = value ;
Value:
Variable = application[" name "]; the Object type is stored in the application and needs to be transformed when taken
Global.asax Files: Global application Classes
Application consists of 5 Events
Application_Start
Application_End
Application_Error
Session_Start
Session_End
The Lock () operation is required when using application , eg:
Statistics function, in the Application_Start event:
Application.Lock ();
application["Count"] = 0;
Application.UnLock ();
To achieve self-increment in Session_Start:
Application.Lock ();
application["Count"]= (int) application["Count"]+1; Required type conversion ;
Application.UnLock ();
SixRequestand theServerProperties
Browser type:Request.Browser.Browser
Browser version:Request.Browser.Version
Client operating system version:Rquest.Browser.PlatForm
Client IP Address:request.userhostaddress
Client host Name:request.userhostname
Server name:server.machinename
Server root directory:server.mappath
Asp. NET collation: cookie,application,session, page life cycle