One, IIS
1. First know what IIS is: It is a Web server software that is installed on the server, accepts requests from the client, and transmits it to the server side, then responds to the request and sends it back to the client. Similar to the waiter in the restaurant.
2. Install iis--Control Panel-Programs-turn Windows features on or off
3. Basic settings are made: After the installation is complete, open the Control Panel-Administrative Tools-iis
Application Pools--settings. Net4.0 Frame
Default directory: Virtual directory under C:\inetpub directory: Virtual directory can be set on another disk
Two, establish. NET Web Project
1. FILE-New-website
File system and HTTP are selectable at file location
HTTP: is a project created and run with IIS
File system: Create and run projects using VS comes with IIS Express, which is typically created by default with this method
2. After entering the interface
App_Code: System folder. All. cs Separate class files are placed in the App_Code folder. (That is, all data access classes and DA files)
Web. config configuration file. The program configuration content is placed inside, usually used to put the link string.
Page files:. aspx (Design interface) and. Aspx.cs (source code), which automatically synthesize a class when compiling or running.
3. Case: Dynamically display database information on the page
1. Create a new table in the DIV and add the first row of data
2. Generate the following lines dynamically using C # code
<div> Note that no input data is required inside the:<%%>, which contains the C # code to execute
<%=%> need to input data, which contains the data to be displayed
Description: Import namespaces in Aspx.cs with using xxxxx import;. Import namespaces in ASPX using <%@ import namespace= "XXXXX"%> import.
Three, five commonly used objects under the web
1.request--GET Request
String s=request[""]; Fill in the address bar inside the brackets? Name of the next name value pair or the name of the form element
string D1 = request["TextBox1"];
2.response--Response Request
Response.Write ("string"); The server's program code enters a string of characters into the page.
Response.Redirect ("redirect page"); redirect page to specified page
Note: All Web programs are stateless. That is, this page is not related to the next Open sub-page or to the previous parent page, and does not pass a value
The reason is that the HTTP protocol they use is inherently stateless.
Performance: Each page returned to the customer is unrelated to the previous or subsequent page, unable to access the data on the previous page, or sending data for subsequent pages.
Workaround: Data that is specifically stored on the server side or client by using several objects to store the relevant state.
Objects that store state on the server: Session and Application
Objects in the client store state: Cookies
3.Session: Each independent browser will create a separate session, not a computer a session
Session stored data is shared in the current session, and closing sessions disappears
Features: Session within 20 minutes if there is no session operation, it will be automatically released
Syntax: (1) Use the Session value: session["key Name"] = value; Value, which is not just a string, it can be an object.
(2) value from Session: type variable name = (cast type name) session["key Name"]
(3) Release Session: Release a session:session["key name"]=NULL;
Release all Session:Session.clear ();
Automatic release: 20 minutes
4. Case studies
Login interface, after successful login to another interface and display "welcome you XXX" plus the current time
I, Login interface
protected void Button1_Click (object sender, EventArgs e) { if (TextBox1.Text.Length > 0 && TextBox2.Text.Length > 0) { session["user"] = TextBox1.Text; Response.Redirect ("default.aspx"); } }
II, Display page
protected void Page_Load (object sender, EventArgs e) { if (session["user"] = = null) { Response.Redirect ("default2.aspx"); } if (session["test"] = = null) { session["test"] = DateTime.Now.ToString (); } Label1.Text = "Welcome:" +session["User". ToString () + "<br/>"; Label1.Text +=session.sessionid+ " " + session["test"]. ToString (); }
4.Application: All sessions share a application space, and any person changes the content of application, others will find it changed. Content in application is not automatically released
(1) Application value: application["key Name"] = value; Value, which is not just a string, it can be an object.
(2) Application value: Type variable name = (cast type name) application["key Name"]
(3) Determine if a value exists in the application
if (application["key Name"] = = null)
{
}
(4) Release application:application["Key name"] = NULL;
Case: Each access page will accumulate the number of visits
protected void Page_Load (object sender, EventArgs e) { if (application["count"] = = null) { application ["count"] = 0; } application["Count"] = (int) application["Count"] + 1; Label1.Text = application["Count"]. ToString (); }
5.Cookie: The presence of client memory or on the hard disk
A temporary cookie is present in the browser memory and persistent cookie is present in the browser-related cookie directory on the computer's hard disk.
Set cookies
response.cookies["key Name"]. Expires = Expiration time.
response.cookies["key Name"]. Value = values.
Read cookies
string s = request.cookies["key Name"]. ToString ();
Case: Setting a cookie Login (remember user name, 30 days free login)
protected void button2_click (object sender, EventArgs e) { if (TextBox1.Text.Length > 0 && TextBox2.Text.Length > 0) { if (checkbox1.checked = = True) { response.cookies["user"]. Expires = DateTime.Now.AddDays (+); } response.cookies["User"]. Value = TextBox1.Text; Response.Redirect ("default5.aspx"); } }
To jump to the page after successful login, click Exit to log back in and clear cookies
protected void Page_Load (object sender, EventArgs e) { if (request.cookies["user"] = = null) { Response.Redirect ("default2.aspx"); } Label1.Text = request.cookies["User"]. Value; } protected void Button1_Click (object sender, EventArgs e) { response.cookies["user"]. Expires = DateTime.Now.AddDays (-1);//expiry date is yesterday, that is, clear the cookie Response.Redirect ("default2.aspx"); }
WebForm Basic Introduction