Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the objects in ASP.NET

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "what are the objects in ASP.NET". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Several objects in asp.net:

1.Request: you can access information about individuals or processes that request Web pages

2.Response: provides a way to accurately control how the response is sent back to the person who made the request

3.Server: provides a series of useful Web-related utilities.

4.Application: provides a useful Web site storage location for frequently used information

5.Session: you can store information for each user's session.

Object Request in ASP.NET

Request can access information about the person or process that requested the Web page. Request objects can effectively deliver messages to us from personal Web browsers.

The two more useful attributes are:

Cookies: you can view the cookies of visitors who were previously on this site through this property.

QueryString: returns any parameters that are transferred to the page using GET.

Object Response in ASP.NET

Response provides a way to control exactly how the response is sent back to the person who made the request. The Response object can access the http response that is about to be sent back to the requesting Web browser.

Common attributes:

1. Redirect: it redirects the user to another page

2. Write: writes a string to the html stream.

Server

Object Server in ASP.NET

Provides a series of useful Web-related utilities.

Common attributes:

MapPath: this property takes a parameter of a virtual path

For example, MapPath ("/ webapp/myfile.aspx") returns the exact location of the file on the physical disk

State processing:

Including Application,Session,Cookies

The main attention should be paid to the scope of the state, the location of the state storage, how to change the state and so on.

Object Application in ASP.NET

Application provides a useful Web site storage location for frequently used information

The information in Application can be accessed by all pages of the site.

Initial configuration of Application:

Configure the initial state when the application starts, in Global.asax

Protected void Application_Start (Object sender, EventArgs e) {Application ["UserCount"] = 0;}

Use Lock and Unlock to avoid changing the state of both pages at the same time

Application.Lock (); Application ["UserCount"] = (int) Application ["UserCount"] + 1; Application.UnLock ()

Application explains a few points:

1. It is used for frequently used data, and if used only occasionally, you can store the information in a file on disk, and in most cases, web.config files can accomplish this task.

2. The Application object is a collection object, which not only contains text information, but also stores objects.

3. If the site starts with a lot of traffic, use Web.config files instead of Application status

Object Session in ASP.NET

It can store information for each user's session. The default timeout is 20 minutes, which ends automatically when the user closes the page.

Common attributes:

Abandon (): this method ends the current session and knows all the information in the session.

Clear (): clears all information in the session without ending the session.

IsNewSession: if a painting is created when the user visits the current page, this property returns true, which is useful when you need to initialize the session with some data before using it.

TimeOut: this property gets and sets idle time in minutes before the end of the session. The default time is 20 minutes

If (Session ["test"] = = null) {Session ["test"] = 1;} else {Session ["test"] = (int) Session ["test"] + 1;}

Session description:

1. Stored on the Web server

2. The actual information is related to each visitor.

3. It is a collection of objects that can be stored.

4. don't store things that don't last a long time in a session, don't store a lot of things in a session.

Cookies

Store small pieces of information related to each user, usually also related to the website. It is stored on the user's hard drive and is usually longer than the expiration date of the Session.

Lifetime settings for Cookies

DateTime dt = DateTime.Now; TimeSpan timeSpan = new TimeSpan; / / 30 days if (Request.Cookies ["test"]! = null) {Request.Cookies ["test"]. Expires = dt.Add (timeSpan);} cookies example if (Request.Cookies ["test"] = = null) {int I = 1; HttpCookie c = new HttpCookie ("test"); c.Value = "1" Request.Cookies.Add (c);} else {int k = Convert.ToInt32 (Request.Cookies ["test"] .value) + 1; Request.Cookies ["test"]. Value = k.ToString ();} "what are the objects in ASP.NET"? thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report