Note: This article is mainly for reference to ASP. NET evening notes. I added my own documents.
Objects that can be used without the need for new during Asp.net development, such:
Request, response, server, session, Cookie, Application
All webpages in Asp.net inherit from the class system. Web. UI. Page. HTTP is a stateless protocol, that is, it does not remember who requested it last time and does not take the initiative to ask the client. The server will respond only after the client initiates a request.
3,Server
A server object is an object used to obtain server-related information. The common method is as follows:
property name |
return value type |
description |
execute |
void |
execute the specified resource and run the Code |
htmldecode |
string |
eliminate the impact on special string encoding |
htmlencode |
string |
encode special strings |
mappath |
string |
obtain the weak path of the specified relative path on the server |
transfer |
void |
stop the current Program and run the specified resource |
mappath |
string |
decodes path strings |
urlencode |
string |
encode the path string |
In terms of concept, the above methods seem to make it difficult to distinguish what they actually do, especially excure/transfer, htmlencode (htmldecode)/urlencode (urldecode. Before talking about them, let's first talk about the role of the mappath method. When we upload files, we need to save the uploaded files to the server in a physical path. What we use most is the relative URL address, this method converts the relative URL address to the physical path of the server.
Example: (create An ASPX page for a single page and then repeat the following code)Examples of common methods for server objects
<% @ Page Language = " C # " Contenttype = " Text/html " Responseencoding = " Gb2312 " %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head >
< Meta HTTP-equiv = "Content-Type" Content = "Text/html; charset = gb2312" />
< Title > Examples of common methods for server objects </ Title >
</ Head >
< Body >
< Ul >
< Li > Server. mappath (".") = <% = Server. mappath ( " . " ) %> </ Li >
< Li > <% = Server. htmlencode ( " <H1> Asp.net night talk 2: Asp.net built-in object " ) %> </ Li >
< Li > < H1 > Asp.net night talk II: Asp.net built-in object </ H1 > </ Li >
< Li > <% = Server. urlencode ( " <A href = \ " HTTP: // Blog.csdn.net / Zhoufoxcn \ " > Zhou Gong's column </a> " ) %> </ Li >
< Li > < A Href = "Http://blog.csdn.net/zhoufoxcn" > Zhou Gong's column </ A > </ Li >
</ Ul >
</ Body >
</ Html >
The effect is as follows:
In the above example, we want to output HTML code on the webpage. If direct output is often ineffective, we can use the htmlencode method to encode the HTML code to be output, in this way, the HTML code is displayed when output to the browser, rather than the HTML effect. The htmldecode method is used to eliminate this impact.
If we output the string <a href = "http://blog.csdn.net/zhoufoxcn"> Zhou Gong's column </a>, a hyperlink is displayed on the page, however, sometimes we want to use this hyperlink as a parameter of querystring. Because of the special nature of URL addresses, such as ":", "/", and other strings have special meanings in the URL address, to output these characters, you cannot directly output them. You need to perform some conversion and convert them back in the future. After urlencode conversion, ":" and "/" are converted into characters such as "% 3A" and "% 2f", and the Chinese characters are also converted. The urldecode method converts characters such as "% 3A" and "% 2f" to the ones we originally wanted to represent.